WebSocket & Real-Time
Real-time web communication: WebSocket protocol, SSE, Socket.IO, STOMP, backpressure, and reconnection strategies.
- WebSocket /ˈwebsɒkɪt/
Full-duplex communication protocol over a single persistent TCP connection; established via an HTTP upgrade handshake.
"We switched the live dashboard from polling every 5 seconds to a WebSocket connection — latency dropped from 5s to under 50ms."
- handshake /ˈhændʃeɪk/
The initial HTTP GET request with an Upgrade: websocket header that transitions the connection from HTTP to the WebSocket protocol.
"The handshake response returns 101 Switching Protocols — after this the connection is a full-duplex WebSocket channel."
- full-duplex /fʊl ˈdjuːpleks/
Communication mode where both client and server can send messages independently and simultaneously over the same connection.
"Full-duplex means the server can push a notification to the client at any moment, while the client simultaneously sends user actions — no turn-taking required."
- Server-Sent Events (SSE) /ˈsɜːvər sent ɪˈvents/
One-way server-to-client streaming over a persistent HTTP connection; simpler than WebSocket for push notifications that flow only from server to client.
"The news feed uses SSE — the server pushes new articles as text/event-stream and the browser's EventSource API handles reconnection automatically."
- long polling /lɒŋ ˈpəʊlɪŋ/
Client sends a request and the server holds it open until new data is available, then responds and the client immediately sends another request.
"Before WebSocket support was widespread we used long polling — the server held each request for up to 30 seconds before responding with an empty body."
- heartbeat /ˈhɑːtbiːt/
Periodic ping/pong frames exchanged between client and server to keep the connection alive and detect silently dead connections.
"Our server sends a ping frame every 30 seconds — if it receives no pong within 10 seconds it closes and the client reconnects."
- message framing /ˈmesɪdʒ ˈfreɪmɪŋ/
The WebSocket binary format where each message has an opcode (text/binary/ping/pong/close), a masking key for client frames, and a variable-length payload header.
"Understanding message framing helps when implementing a custom WebSocket server — the first two bytes encode the opcode, masking flag, and payload length."
- backpressure /ˈbækpreʃər/
Condition where a fast sender produces messages faster than a slow receiver can process them; must be handled to avoid unbounded memory growth.
"The writable stream's write() returned false, signalling backpressure — we paused reading from the WebSocket until the drain event fired."
- Socket.IO room /ˈsɒkɪt aɪ əʊ ruːm/
Named group within a Socket.IO server; a socket can join multiple rooms and events broadcast to a room are received only by its members.
"Each collaborative document gets a room named by its ID — joins, edits, and cursor positions are emitted only to users in that room."
- Socket.IO namespace /ˈsɒkɪt aɪ əʊ ˈneɪmspeɪs/
Virtual partition within a Socket.IO server identified by a path like /chat or /admin; sockets in different namespaces cannot communicate directly.
"We use /notifications and /chat as separate namespaces so the notification service can be scaled independently of the chat service."
- STOMP /stɒmp/
Simple Text Orientated Messaging Protocol; a text-based messaging protocol that runs over WebSocket for publish/subscribe and point-to-point messaging.
"The Spring Boot backend exposes a STOMP broker endpoint — the JavaScript client subscribes to /topic/prices and receives live market data."
- presence channel /ˈprezəns ˈtʃænəl/
Real-time channel that tracks which users are currently connected; used for online status indicators, typing indicators, and collaborative cursors.
"The presence channel broadcasts join and leave events so every participant's avatar lights up or greys out as teammates connect."
- reconnection strategy /ˌriːkəˈnekʃən ˈstrætədʒi/
Logic to automatically re-establish a dropped WebSocket connection using exponential backoff with jitter to avoid thundering-herd reconnect storms.
"Our reconnection strategy starts with a 1s delay and doubles it on each failure up to 30s, with ±30% jitter to spread reconnect attempts across clients."
- WebRTC data channel /web ɑː tiː siː ˈdeɪtə ˈtʃænəl/
Peer-to-peer channel for transmitting arbitrary binary or text data directly between browsers; no server relay required after the initial signalling.
"File transfer in our collaboration tool uses a WebRTC data channel — large files flow directly peer-to-peer without passing through our server."
- connection state /kəˈnekʃən steɪt/
The WebSocket connection lifecycle: CONNECTING (0), OPEN (1), CLOSING (2), CLOSED (3). Always check readyState before sending.
"We guard every send call with if (ws.readyState === WebSocket.OPEN) to avoid throwing when the connection is closing."
Quick Quiz — WebSocket & Real-Time
Test yourself on these 15 terms. You'll answer 10 multiple-choice questions — each shows a term, you pick the correct definition.
What does this term mean?