System Design · Senior · Question 11 of 75
How do you scale WebSocket servers horizontally?
- ✓Correct answer: Connect nodes via pub/sub for delivery between them
- 2Keep all connections on one server with lots of memory
- 3Reconnect clients to a random node on every message
Explanation
Users of the same chat are connected to different nodes. The node that receives a message publishes it to a bus, and nodes with subscribers deliver it to their connections. The load balancer must support long-lived connections; during deploys clients reconnect gradually.