What is Redis Pub/Sub and how does it help with WebSocket scaling?
Answer
When WebSocket servers scale horizontally, a message sent to a client on Server A cannot reach a client connected to Server B — they have separate in-memory connection pools. Redis Pub/Sub solves this by acting as a message broker between server instances. Each server instance subscribes to Redis channels relevant to its clients. When Server A needs to send a message to all users in room "game-42", it publishes to the Redis channel room:game-42. Redis delivers that message to all subscribers — Server A, B, and C all receive it and each forward it to their local connections in that room. Socket.IO's @socket.io/redis-adapter implements this pattern automatically: you just configure the Redis connection and io.to(room).emit() works correctly across all instances without code changes.
Previous
How do WebSockets work behind a load balancer?
Next
How do you implement presence (online/offline) with WebSockets?
More WebSockets & Real-time Questions
View all →- Intermediate How do you implement a WebSocket server in Node.js using the `ws` library?
- Intermediate What are Socket.IO rooms and namespaces?
- Intermediate How do you handle WebSocket reconnection logic?
- Intermediate What is the difference between Socket.IO and raw WebSockets?
- Intermediate How do you authenticate WebSocket connections?