Getting data pushed to clients
HTTP has a built-in asymmetry: clients ask, servers answer. Servers can't just call you up. So what happens when the server has news — a new chat message, a live score update — and needs the client to know now? Four techniques, in rising order of power and cost. The art is picking the cheapest one that meets your actual latency need.
1. Short polling: "anything new? ...anything new?"
The client simply asks every N seconds. Like a kid in the back seat asking "are we there yet?" on a timer. It's dumb, stateless, trivially scalable — every request is a normal HTTP request, nothing special anywhere — and gloriously simple to debug.
The cost is waste, and it scales badly: 1 million clients polling every 5 seconds = 200,000 requests per second, almost all of which return "nothing new." You're paying peak-traffic infrastructure to deliver mostly empty envelopes. Fine for small client counts or genuinely slow-changing data (a dashboard refreshing every minute). Wrong for real-time anything at scale.
2. Long polling: "I'll wait on the line"
Clever twist: the client asks, and the server doesn't answer until it has something to say (or a ~30-second timeout passes). The moment news arrives, the held request completes, and the client immediately asks again. From the outside it feels near-real-time, using nothing but ordinary HTTP — which is why it was the standard trick for years.
The hidden cost: the server is now holding thousands of open connections, each consuming a socket and memory. You're paying most of the resource price of WebSockets while getting fewer of the benefits. Today it's mainly a fallback for environments where the better options are blocked.
3. Server-Sent Events: a one-way news ticker
SSE opens one long-lived HTTP connection down which the server pushes a stream of text events, whenever it likes. The browser support is built-in and delightful: automatic reconnection, and a Last-Event-ID mechanism so a client that dropped for 10 seconds resumes exactly where it left off — no missed events, no custom code.
The one limit: strictly one direction, server → client. (The client can still send things via ordinary separate HTTP requests.) That makes SSE perfect for notification feeds, live scores, progress bars, and streaming an LLM's tokens as it generates. It is criminally underused because people reflexively jump to WebSockets — see the trap.
4. WebSockets: a real two-way phone call
A WebSocket starts as HTTP, then upgrades into a persistent, full-duplex pipe: both sides send freely, anytime, minimal per-message overhead. This is the right answer when the client also talks frequently: chat, collaborative editing, multiplayer games, live trading.
But now you've bought state, and state is expensive. Your servers hold live connections, which means: load balancers must route each user's traffic consistently (or you add a shared pub/sub layer so any server can reach any user); scaling means tracking which server holds which user — a registry problem you'll design for real in the chat lab; every deploy drops thousands of connections at once, so reconnection storms and message replay become your problems to engineer. WebSockets are the most powerful tool and the most expensive to operate. Buy them when you need them.
| Updates every few minutes | Poll |
| Server → client, realtime | SSE |
| Both directions, realtime | WebSocket |
| Mobile, battery matters | Push notification service |
That last row matters: on phones, a persistent connection drains battery, so when the app is backgrounded you hand delivery to the OS's push service (APNs on Apple, FCM on Android) — one shared connection the OS maintains for all apps. This becomes a component in the chat and notification labs.
WebSockets for a notification bell. You've made every deploy a mass-reconnect event and every load balancer config a research project — to deliver updates a 30-second poll or a simple SSE stream would have handled. Match the tool to the actual latency requirement, not to the most exciting demo.