I'm looking for a system to create a live sockets application through sockets.io and that can be balanced without problem.
There are tons of solutions to balance the load between multiple socket instances, like SocketCluster, but the problem I'm facing is that, when the load balancer decides that instead of 10 instances I need 8 instances and closes 2 of them, how can I keep the socket connections of those instances?
Trying to explain it better, I have an event streaming company that streams events almost all weekends but nothing in between. If I use Amazon EC2 I'm only going to have 1 instance along the time that there are almost 0 users connected, but in the weekend Amazon will launch some instances when an event starts streaming and will route each connection to a different server. The problem that I see is, when an event ends and people starts quitting, the load balancer will start closing instances and people still connected to those instances will start losing connection to the chat. I know that I can overcome this simply by reconnecting the people but is possible that they lose some messages meanwhile they reconnect.
Is there a system that will route the connection to another server and know that was the same user that was connected to the other instance without reconnecting?
You can't keep connections to a server process that gets closed. A socket is a connection between two specific endpoints. For security reasons, you can't just remap one of the endpoints to a new server. Instead, you would have to tear down the socket and let it reconnect (which socket.io will do for you automatically) and then get rebalanced into the new configuration when it connects again.