WebSocket Cluster Backplane Lab (Interactive)
Pin Alice and Bob to different WS servers and see who gets the message once the Redis Pub/Sub backplane drops. Grow a WebSocket fleet, toggle the message backplane and Ping/Pong heartbeats, and trace room fan-out plus the 2-6 byte frame economics versus HTTP headers.
WebSocket Fleet & Redis Pub/Sub Backplane
Alice on Server 0 messages Bob on Server N. Persistent sockets live in one server's memory — can it fan out?
WS Server 0
8 (Alice) sockets
~0.1 MB kernel mem
WS Server 1
8 sockets
~0.1 MB kernel mem
WS Server 2
8 (Bob) sockets
~0.1 MB kernel mem
FAN-OUT TRACE
› Handshake done: HTTP/1.1 101 Switching Protocols → binary frames. Press “Alice sends”.
Cluster controls
Wire cost per message (x24 clients)
WebSocket frames: 144 B (2–6 B after 101 upgrade)
HTTP poll headers: 24,000 B (~1 KB each)
WS is ~167× lighter per message on the wire.
How It Works Under the Hood
After the HTTP/1.1 101 Switching Protocols upgrade, a WebSocket is a persistent full-duplex TCP socket whose frames cost only 2-6 bytes instead of ~1KB of HTTP headers. That persistence creates a scaling problem: sockets live in one server's memory, so when Alice on Server 0 messages a room, any Bob on Server 3 is unreachable — the cross-server dilemma. Production fleets solve it with a Redis Pub/Sub or Kafka backplane: the receiving server publishes to a room channel, and every server pushes the frame down its local sockets in under 10ms, while 30-second Ping/Pong heartbeats stop NATs from silently reaping idle connections.
Core Architectural Principles
- HTTP 101 upgrade handshake turns one TCP socket into full-duplex 2-6 byte framed transport.
- Backplane fan-out: Server 0 publishes chat:room_12 to Redis; all servers deliver to their local sockets.
- Least-Connections balancing plus 30s Ping/Pong heartbeats against aggressive NATs and firewalls.
In a chat design, draw the backplane immediately: WS servers are stateful islands, so connect them with Redis Pub/Sub or Kafka on room channels. Mention the 101 handshake, 2-6 byte framing versus ~1KB HTTP headers, heartbeat frames for NAT liveness, and graceful reconnect logic because rolling deploys sever persistent sockets.
Sub-10ms bidirectional messaging at minimal wire overhead, versus stateful connections that complicate autoscaling, deploys, and require a broker backplane.