Problem
Interactive applications such as chat, collaboration and games need both sides to send messages at any time. HTTP request-response forces polling or workarounds that add latency and overhead.
Also known as: websocket, full-duplex-channel
Provide a persistent bidirectional channel between client and server for low-latency interactive messaging.
Interactive applications such as chat, collaboration and games need both sides to send messages at any time. HTTP request-response forces polling or workarounds that add latency and overhead.
WebSockets upgrade an HTTP connection into a persistent, full-duplex channel. Either side can send frames at any time with just a few bytes of overhead, which suits interactive features that would be clumsy over request-response.
The client sends a GET with Upgrade: websocket; the server replies 101 Switching Protocols. From then on both sides exchange frames.
client node A backplane node B
|--- upgrade ---------->|
|<-- 101 ---------------|
|--- msg to room 7 ---->|--publish---->|--deliver--->| other users
Since a user is connected to one node, messages for room 7 are published to a backplane, and each node forwards to its local subscribers. Authenticate during the handshake, then authorise each message. Track a sequence number per stream so a reconnecting client can ask for messages after the last one it saw.
Medium - connection-holding servers and backplane
High - state, deploy draining, monitoring
Medium - protocol and lifecycle design
Silent dead connections without heartbeats
Reconnect storm after deploy or node loss
Messages lost or duplicated across reconnects