Polling, long polling, SSE and WebSockets
coreintermediateThese are the four standard ways a client gets near-real-time data from a server. Polling repeats a plain request every few seconds regardless of whether anything changed. Long polling holds each request open until the server actually has something to say, then the client immediately reopens it. Server-Sent Events (SSE) is a single long-lived HTTP connection the server keeps pushing text events down, one direction only, with the browser reconnecting automatically if it drops. WebSockets upgrade one HTTP handshake into a persistent, full-duplex socket where either side can send a message at any time. Each option trades implementation simplicity and infrastructure compatibility for how immediate and how bidirectional the communication can be.
Think of it as
Think of four ways to find out if a friend has replied to your message. Polling is calling them every five minutes to ask "anything new?" — simple, but wasteful and never quite up to date. Long polling is calling once and asking them to stay on the line until they actually have something to tell you, then you hang up and immediately call back. SSE is like leaving a walkie-talkie on their desk that only they can talk into — they push updates to you whenever they want, but you can't talk back on it. A WebSocket is a real phone call left open — either of you can speak at any moment, and the line stays live until someone hangs up.
What we're doing: Compare what actually happens on the wire for long polling vs SSE when a chat message arrives.
- 4
- Long polling closes the HTTP request after every single message — step 5 has to open a brand new one before the next message can arrive.
- 12
- SSE never closes the connection between messages — step 7 reuses the exact same open connection from step 1, which is why SSE avoids the reconnect overhead long polling pays per message.
Why this works: The difference is not just "who talks first" — it's that long polling pays a full request/response round trip per message, while SSE pays that cost once per connection no matter how many messages flow afterward.
Reaching for WebSockets by default because they seem the most "modern" option
Wrong
Better
What you see: A team ships a WebSocket server, plus custom reconnect and heartbeat logic, plus load-balancer configuration for sticky sessions and upgrade support — for a feed that only ever flows one direction and never needed the client to send anything back.
Why: WebSockets add real operational cost: connection-aware load balancing, manual reconnect/heartbeat logic, and infrastructure that must support the HTTP Upgrade handshake end-to-end. If the data only ever flows server-to-client, SSE gets the same low latency with a simpler, plain-HTTP transport and a browser-managed reconnect built in.
- Polling — fixed interval, always wasteful
- Long polling — held open until data arrives
- SSE — server push, one direction
- WebSockets — full-duplex, most infra cost
The four transports compared
Remember: Polling: simplest, wastes requests, laggy. Long polling: lower latency, one request per message, ties up a server slot while waiting. SSE: server push over plain HTTP, one direction, auto-reconnect built in. WebSockets: full-duplex, needs upgrade support everywhere in the path, most infrastructure cost.
See also: choosing a transport · connection lifecycle and backpressure

