WebSockets vs Server-Sent Events vs polling: real-time options compared
Chat apps, live dashboards, notifications and collaborative editors all need the server to push updates to the browser. There are several ways to do it.
Polling
The browser asks "anything new?" every few seconds.
- Simple and works everywhere
- Wasteful when nothing changes; adds latency equal to the interval
- Fine for low-frequency updates, like checking job status
Long polling
The browser sends a request and the server holds it open until there's news, then the browser immediately asks again.
- Lower latency than regular polling
- More server connections to manage
Server-Sent Events (SSE)
A single long-lived HTTP response that the server streams events through.
- One-way: server to browser
- Built-in reconnection and event IDs in the browser's EventSource API
- Works over regular HTTP, which plays nicely with many proxies
- Good for notifications, live feeds and streaming text responses
WebSockets
A persistent, two-way connection upgraded from HTTP.
- Low latency in both directions
- Ideal for chat, multiplayer games and collaborative editing
- You handle reconnection, heartbeats and message formats yourself or via a library
- Scaling requires care: sticky connections and a way to share messages between servers
How to choose
- Updates rare? Polling.
- Server pushes, client rarely sends? SSE.
- Frequent messages both ways? WebSockets.
Managed real-time services can take on the scaling work if you'd rather not run it.
What do you use for real-time features? Has SSE been enough where you expected to need WebSockets?
Comments · 4
As a beginner, polling sounded the simplest, and then I learned how much wasted traffic it creates. SSE seems like a nice middle ground for one-way updates.
For an MVP, start with the simplest option that works. Short polling is fine for a few hundred users, and you can upgrade once usage justifies it.
If I need two-way chat, is WebSockets always the answer, or are there cases where SSE plus normal requests would do?
SSE for server-to-client updates plus regular HTTP posts for sending messages can work for simple chat. WebSockets shine when you need low-latency two-way flow.