Reputation: 79
I am trying to scale socket.io running on restify. I was able to set it up to run great on one nodejs instance. Now when I scale my app to four instances, the app ecosystem broke (i.e., events were not synched correctly between clients).
I'm looking for examples on how to set up sticky sessions with restify. Or, how is it being done nowadays?
The update on sticky session was a year ago: Socket 1.0 Update / Scalability.
I found these two blogs on setting this up but they both used Express and were also written more than a year ago:
As I am making a headless API, I think Express should not be used. Is it the recommended way of thinking or I should just use Express?
package.json:
"dependencies": {
"hiredis": "^0.4.1",
"pouchdb": "^4.0.3",
"pouchdb-upsert": "^1.1.3",
"redis": "^2.0.1",
"restify": "^4.0.0",
"socket.io": "^1.3.7"
}
Any help would be appreciated!
Upvotes: 4
Views: 332
Reputation: 345
Socket.io will only keep your server <-> client data synced in a single instance due to the fact that Node is single-threaded and lives on a single CPU core. To sync multiple instances, you'll need a higher level message management method. Socket.io recommends an instance of Redis. There also this repo: http://socketcluster.io which handles the same issues for you.
Upvotes: 1