4 ms·
Ask HN: 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.
- tomthumb 5y agoIf you select the first option (multiple domains), the load balancing would be done by the client ( hit one domain, on failure hit next.)
- jcun4128 5y agoIt looks like the other thing I'm missing is the shared database. Which idk if Postgres counts, my stuff is not that high performance but wondering if I need something else like Redis.
- joshxyz 5y agoHmmm, 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://github.com/uNetworking/uWebSockets.js - https://12factor.net/ https://12factor.net/
- jcun4128 5y agothanks for the insight