All three let a server send updates to a browser without the user refreshing the page. Long polling is plain HTTP: the client sends a request, the server holds it open until there is news or a timeout, and the client immediately asks again. Server-Sent Events (SSE) keep one HTTP response open and stream text events from server to client, and the browser's EventSource API reconnects automatically. WebSockets upgrade an HTTP connection to a persistent, full-duplex channel where both sides can send messages at any time. Use SSE for one-way streams such as live scores, dashboards or streaming LLM output, WebSockets for two-way interactive traffic such as chat, collaborative editing or games, and long polling when you need the widest compatibility or updates are infrequent.
Three ways to get live updates into a browser. Watch the same messages travel down each lane. Long polling is plain HTTP. The client asks, and the server holds the request open until there's news. It answers, and the client immediately asks again. Every message costs a full request and response. Server-Sent Events open one HTTP response and keep it streaming. Each event is a few bytes of framing, it only flows from server to client, and the browser reconnects on its own, resuming from the last event ID. WebSockets upgrade the connection into a full-duplex channel. Both sides send small frames whenever they like, text or binary. The catch, for both streaming options: each user is pinned to one gateway server, so a message has to find the gateway that holds the recipient's connection. So pick by direction. One-way feeds, like live scores or streamed AI tokens, suit SSE. Chat, games and shared cursors need WebSockets. And long polling is the fallback that works through almost anything.
| Aspect | Long polling | WebSockets | Server-Sent Events |
|---|---|---|---|
| Direction | Server to client, one response per request | Both directions at any time | Server to client only |
| Transport | Repeated HTTP requests | HTTP upgrade to the WebSocket protocol over one TCP connection | One long-lived HTTP response (text/event-stream) |
| Per-message overhead | A full HTTP request and response | A small frame header | A few bytes of event framing |
| Reconnect and resume | Natural: every request is new | You build it yourself | Built in: automatic reconnect with Last-Event-ID |
| Data | Anything HTTP can carry | Text or binary | UTF-8 text only |
| Infrastructure | Works through almost any proxy | Proxies and load balancers must support the upgrade and long-lived connections | Plain HTTP, but buffering proxies must be set to flush |
| Good fit | Infrequent updates, fallback paths | Chat, multiplayer, collaborative editing, trading screens | Live scores, notifications, dashboards, token streaming |
Long polling
Updates are infrequent and you want plain request and response semantics.
WebSockets
The client sends frequent messages too, not just the server.
Server-Sent Events
Traffic is one way, from server to client.
WebSockets and SSE make the gateway tier stateful: each user is attached to one server. When a message for that user is produced elsewhere, the system has to find the right gateway. The usual pattern keeps a registry from user ID to gateway, or has every gateway subscribe to a pub/sub channel for the users it holds, so producers publish once and the owning gateway delivers.
Long-lived connections also change capacity planning. A gateway is limited by open connections and memory per connection more than by requests per second. Plan for heartbeats to detect dead connections, for load balancer idle timeouts, and for the reconnect storm when a gateway restarts and all of its clients come back at once.
Over HTTP/1.1, browsers cap the number of connections per host at a small number, so several SSE streams in different tabs can exhaust it. Over HTTP/2 the streams share one connection and the cap stops being a problem. SSE carries only text, so binary data has to be encoded. WebSocket messages have no built-in acknowledgment or resume, so chat systems add message IDs and a sync call on reconnect to fetch anything missed.
Any real-time feature leads here: chat, presence, live comments, scores, collaborative editing and streamed AI responses. Pick one, say why its direction and delivery guarantees fit the feature, then spend most of the time on how messages find the right connection and what happens on reconnect.
“For chat I would use WebSockets because both sides send frequently. Each gateway registers its connected users in Redis, and when a message arrives the chat service looks up the recipient's gateway and forwards it there. On reconnect the client sends the last message ID it saw and fetches anything newer, so a dropped connection never loses messages.”
For one-way server-to-client streams, SSE is usually simpler: it is plain HTTP, reconnects on its own and resumes from the last event ID. When the client also sends frequent messages, WebSockets fit better.
No. SSE carries UTF-8 text, so binary data must be encoded, for example as base64, or sent over a different channel.
Yes, as a fallback where streaming connections are blocked and for features with infrequent updates. It also keeps the server side simple because every exchange is an ordinary request.
Yes, if the load balancer supports the HTTP upgrade and its idle timeout is longer than your heartbeat interval. Because connections are long lived, rebalancing happens only as clients reconnect.
The full lesson on all three, with framing and failure handling.
Long-lived connections, affinity and health checks.
The backplane that routes messages between gateways.
WebSocket gateways, routing and offline delivery.
Fan-out to a very large audience in real time.
A one-way stream that suits SSE.
Heartbeats and detecting disconnects.
Streaming generated tokens to the browser.
Two-way edits and cursors between collaborators.
Knowing the trade-off is half of it
Practise saying it under follow-up questions: a timed system design interview with an AI interviewer that probes your choices and grades against a rubric.