Problem 1: connection distribution
LB picks a backend. Once picked, stays there for the connection's life. Uneven distribution = hotspots.
Advertisement
Problem 2: cross-instance delivery
User A is on server 1. User B is on server 2. Their messages need to hop. Redis pub/sub or a message broker in the middle.
Advertisement
Redis pub/sub pattern
// Subscriber
redis.subscribe("user:" + userId, msg -> ws.send(msg));
// Publisher (any server)
redis.publish("user:" + userId, message);