Q:

Scaling express/node.js with socket.io horizontally with redis

I am trying to scale by express backend. The problem is that every time a user comes in or if I restart the server it gets a new socket.id. Plus I can't save the whole socket into memory because it gives me a [Circular JSON] problem. How do I save somepart of the socket into redis that will allow me retrieve the same socket from other servers?

A:

You need to decouple the user from the socket.id. The socket.id is volatile and can change even with a browser refresh. Instead, when a user socket connects, take a look at the handshake data which is passed and use that to associate the socket to the user. As far as persisting socket data in redis, that can already be handled for you using socket.io-redis.
Take a look at this link for scaling out socket.io: http://socket.io/docs/using-multiple-nodes

