Networkingwebsocketswswssrfc 6455

WebSocket

Definition

WebSocket (RFC 6455) starts as an HTTP request with Upgrade: websocket; after a 101 Switching Protocols response, the same TCP connection carries framed messages in both directions.

In practice

Chat, multiplayer games, collaborative editors and live dashboards need the server to push updates instantly and the client to send often. A WebSocket avoids polling and the overhead of a new HTTP request per message. Because each socket lives on one server, a pub/sub backplane delivers a message to whichever server holds the recipient's connection.

The servers become stateful: capacity is sized by concurrent open connections and memory per socket, not by requests per second. A server failure or deploy drops thousands of sockets at once, and clients must reconnect with jittered backoff to avoid a reconnect storm. If updates only flow from server to client, Server-Sent Events are simpler.

Example

A gateway holding 200,000 sockets at 20 KB each needs about 4 GB of memory for connections alone; when it restarts, clients reconnect over 30 seconds with random delays.