Polling, long polling, SSE and WebSockets

Four ways to get live updates to a browser, and how to choose between them.

On the roadmap:Beginner · step 8: Real-time basics

Lesson 8 of 23 · 7 min read · quiz · exercise

The problem

HTTP is request and response: the client asks. How does the server tell a browser something now?

The four options

TechniqueHowGoodWeak
Short pollingClient asks every N secondsTrivial, works everywhereWasteful, delayed by N
Long pollingClient asks; the server holds the request until there is news (or a timeout), then the client asks againNear real time, plain HTTPA held request per client, awkward at scale
Server-sent events (SSE)One long HTTP response streams eventsSimple, auto-reconnect, text over HTTPOne-way only
WebSocketsHTTP upgrades to a two-way connectionLow latency both waysStateful connections, more infrastructure

Figure SDA-CORE-08-1 · The four options · © forcsguy.com

Before: polling: keep asking

After: WebSocket: server pushes

What changed

  • No wasted requests when nothing has changed
  • Updates arrive the moment they happen
  • The server must hold many open connections

Choosing

  • Updates are rare or delays are fine: polling.
  • The server pushes, the client mostly listens (feeds, scores, notifications, progress): SSE.
  • Both sides send often (chat, games, collaborative editing): WebSockets.

Running persistent connections

Connections are long-lived, so capacity is about how many connections a server can hold, not requests per second.

  • Put connection handling in servers that are separate from your stateless API.
  • Use heartbeats to detect dead connections, and reconnect with backoff and jitter.
  • Track which server holds which user so messages can be routed (a presence or session store), and use a pub/sub system between servers.
  • When a client reconnects, let it ask for what it missed (events after id X), because connections drop.
  • Authenticate on connect and again when tokens expire.

More on this site

Check your understanding

Question 1 of 3

0 correct so far

What is the drawback of short polling every second?

Topics covered in this lesson

All topics

© 2026 forcsguy.com. Original lesson text and diagrams. Books and sites linked above belong to their authors.