Plain HTTP is request and response: the server can only answer, never start a conversation. For chat, live scores or notifications, the server needs a way to tell you something now. There are four common ways, from simplest to most capable.
Polling
The client asks every few seconds: "Anything new?" Usually the answer is "no".
- Simple, works everywhere.
- Wasteful: most requests return nothing, and you pay for every one.
- Laggy: a message waits up to one polling interval.
Fine for things that change slowly, like checking a report's status every 30 seconds.
Long polling
The client asks "anything new?" and the server holds the request open until there is something (or a timeout, say 30 seconds). As soon as the client gets an answer, it asks again.
- Messages arrive almost instantly.
- Far fewer empty responses than polling.
- Still a new request per message, and each waiting client ties up a connection on the server.
Server-sent events (SSE)
The client opens one HTTP connection and the server keeps streaming events down it, one way: server to client. Browsers support it with a simple API and reconnect automatically.
Great for live feeds, notifications, progress bars and streaming AI responses. If the client needs to send something, it uses ordinary requests.
WebSockets
A WebSocket starts as an HTTP request, then upgrades into a long-lived, two-way connection. Either side can send messages at any time, with very little overhead.
The right tool for chat, multiplayer games and collaborative editing. The cost is on the server: every user holds an open connection, so a million online users means a million connections. Those servers are stateful (they hold your connection), which makes scaling and deploys harder: you need a way to find which server holds Bob's connection, and clients must reconnect when a server restarts.
Choosing
| Feature | Good fit |
|---|---|
| Rare updates, simplicity matters | Polling |
| Server-to-client stream (feeds, notifications, progress) | SSE |
| Two-way, low-latency (chat, games, co-editing) | WebSockets |
| Real-time over infrastructure that blocks the others | Long polling as a fallback |
Key idea: polling asks repeatedly; long polling waits for an answer; SSE streams one way from the server; WebSockets are a two-way open line. Open connections make servers stateful, which is the price of real-time.