HACKER Q&A
📣 jcun4128

Approaches to load balancing web sockets?


Might be simple, just trying to think of sane ways to do it. These are plain web sockets in Web JS to Node not using something like socket.io. It's user A to server to user B and vice versa.

There would be some kind of db involved in the event of it going down/can reconnect people by some ids.

My concern is do you keep say multiple domain options on the app (by env variables) or do you have a single url you hit (no?) and that branches off to different instances.

Scale is small now as in 10/100s of users, performance is not like a video game but still real time/more than text chat. The data rate is still low, mostly transferring meta data.


  👤 joshxyz Accepted Answer ✓
Hmmm, maybe try optimizing with uwebsockets.js? Works well with Caddy, HAProxy, or NGINX?

On cross-domain communications, should be good as long as it's 12-factor where you got a session store / pub-sub mechanism that both servers can use.

- https://github.com/uNetworking/uWebSockets.js

- https://12factor.net/


👤 tomthumb
If you select the first option (multiple domains), the load balancing would be done by the client ( hit one domain, on failure hit next.)