Async and streaming / Intermediate / 6 min
Polling, long polling, SSE or WebSockets
Four ways to push updates to a browser, on the same events: delay, requests and connections compared.
Start the simulation → Change the load, break a part, watch what happens. Free, no sign-up.
In short
- What it is
- Four ways to push news to a browser: short polling, long polling, server-sent events (SSE) and WebSockets.
- Why it matters
- Chat, live prices and notifications need updates within a second without the user refreshing.
- The trade-off
- Polling is simple but wastes requests; WebSockets are fastest but keep a connection open per user, which costs memory and needs sticky routing.
- Say it in an interview
- "WebSockets for two-way chat, SSE for one-way live updates, and long polling as the fallback."
Check yourself
Events are rare. Which strategy wastes the most requests?
Answer: Short polling. Short polling asks on a timer whether or not there is news, so most responses are empty.
You need the server to push updates and the client never sends messages back. Which is simplest?
Answer: Server-Sent Events. SSE is one-way server push over plain HTTP, with automatic reconnects built into browsers.
What is the main server-side cost of WebSockets, SSE and long polling at scale?
Answer: Holding one open connection per connected user. Each user keeps a connection open, so you plan for millions of concurrent connections and sticky routing.