WebSockets
NetworkingAlso known as: WS, WebSocket protocol
WebSockets provide a persistent, full-duplex communication channel over a single TCP connection between a client and server, enabling real-time bidirectional data transfer without the overhead of repeated HTTP requests.
Unlike HTTP's request-response model, WebSockets establish a long-lived connection where both client and server can send messages at any time. The connection starts as an HTTP request with an Upgrade header, then transitions to the WebSocket protocol.
WebSockets are ideal for real-time applications: chat systems, live notifications, collaborative editing, multiplayer games, financial tickers, and live dashboards. Any scenario where the server needs to push data to the client without the client requesting it benefits from WebSockets.
Design considerations include connection management (handling thousands or millions of concurrent connections), reconnection logic (clients should automatically reconnect with exponential backoff), message serialization (JSON, Protocol Buffers), and horizontal scaling (WebSocket connections are stateful, requiring sticky sessions or a pub/sub layer for multi-server setups).
Alternatives include Server-Sent Events (SSE) for server-to-client only streaming, and long polling as a fallback when WebSockets are not supported.
Related Terms
Practice This Concept
Ready to design?
Practice using websockets in a real system design on Supaboard's interactive whiteboard.
Browse Challenges