How it works · 19 of 36 Core
How do chat and live apps get instant updates (WebSocket)?
The line stays open
Live updates (WebSocket): Instead of asking again and again, the app opens one connection that stays open, so the server can push new messages the moment they exist.
Loading the animation…
Say it like this A WebSocket keeps one line open between app and server, so new messages arrive the moment they're sent instead of the app asking again and again.
Under the hood — for builders
- Real case: what the WebSocket standard says it replaced
- The standard opens by naming the problem: chat and game apps used to "poll the server for updates", with an HTTP header on every message. Its fix starts with one handshake:
- Worked example: asking often vs asking rarely
- A friend sends 3 messages a minute. Polling every n seconds means 60 ÷ n asks a minute, and a message waits n ÷ 2 seconds on average:
- Why each message is cheaper on an open line
- Every polling ask carries a full set of HTTP headers. On an open WebSocket, each message carries a frame header of a few bytes:
- Where you meet it
- The standard names its uses: games, stock tickers, apps several people edit at once, and live views of a service.
- Measure it
- Browser: F12 → Network → filter "WS". A live chat page shows one row that stays open, with messages inside it.
- Watch out
- Every connected user holds one open line on the server. Plan servers for the peak number of people online at once.
- Sources
- RFC 6455, The WebSocket Protocol (sections 1.1, 1.2, 5.2). RFC 9110, section 3.9. Read 28 Nov 2026.
What happens in the WebSockets animation, step by step?
- A friend sends you a chat message. It reaches the server in a blink. But how does your phone find out it's there?
- The old way: the app asks "anything new?" again and again. Most answers are "no", and each ask is a whole request.
- Your turn: drag how often the app asks. Watch the delay and the pile of wasted asks.
- A WebSocket asks once to open a line, and the line stays open. The server sends each message down it the moment it arrives.
- No waiting, no wasted asks. The cost: the server must hold one open line for every phone that's connected.
- Instead of asking again and again, the line stays open. Next: what's the difference between a modem and a router?
What everyday example explains WebSockets?
Staying on a phone call instead of redialling every minute.
Why should a team care about WebSockets?
Chat, live scores and multiplayer games depend on it, and it changes how servers must be sized.