AJAX Polling
The simplest form of "real-time" — ask the server every N seconds. Wasteful at scale, perfectly fine more often than people admit, and the baseline every other technique is compared against.
Short polling is setInterval(fetch, n): the client repeatedly asks “anything new?” and the server replies, usually with
nothing. Latency is up to n seconds and most responses are empty. And yet it’s often the right call.
When polling is fine
- Updates are rare or freshness isn’t critical — a job status that changes every few seconds, a dashboard refreshed every minute.
- The infrastructure doesn’t support long-lived connections.
- You want the simplest thing that works and can be cached, retried and load-balanced like any other request.
Making it cheap
The cost is easy to estimate: requests per second ≈ clients ÷ interval. A hundred thousand clients polling every five seconds is twenty thousand requests a second of mostly nothing. So:
- Use conditional requests (
ETag/If-None-Match) so unchanged data returns a tiny304 Not Modified. - Back off when the tab is hidden (
document.visibilityState). - Add jitter so clients don’t synchronise into spikes.
- Let a data library do it: TanStack Query’s
refetchIntervalor SWR’srefreshIntervalhandle most of this for you.
The four techniques side by side
| Technique | Direction | Latency | Server cost | Use when |
|---|---|---|---|---|
| Short polling | client asks | up to the interval | many empty requests | rare updates, simplest infrastructure |
| HTTP Long Polling | server answers when ready | low | held connections | fallback, legacy, job queues |
| Server-Sent Events (SSEs) | server → client | low | one connection per client | feeds, progress, notifications, token streams |
| WebSockets | both ways | lowest | one stateful connection | chat, collaboration, games, trading |
In practice
On a workflow platform I worked on, process status views were a textbook polling case: status changed every few seconds, nobody needed millisecond freshness, and polling with a sensible interval was far simpler to operate than a socket infrastructure. Pick the technique from the freshness your users actually need, not from what sounds most impressive.
- #polling
- #real-time
- #http
- #system-design
↩ Linked from (3)
Internal Developer Platform · Where Platforms Fit: DDD Subdomains · API Modelling · Bulletproof React · Zustand Transient Updates · AJAX Polling
- HTTP Long PollingGrowing
…corporate proxies, and it's still a sensible choice for "poll for jobs" APIs. Compare all four techniques in AJAX Polling.
- WebSocketsEvergreen
…streams) | Server-Sent Events (SSEs) — simpler, plain HTTP | | Updates are rare or freshness isn't critical | AJAX Polling | | Long-lived connections are blocked | HTTP Long Polling |
↪ Links to (3)
Related by topic
- Growingmetaphor
Balance Is a Control Loop
Calisthenics Lab - Growingcase study
Building a Graph Component Library
Frontend craft - Growing
Graph Visualisation Libraries
Real-time UIs - Growing
Heartbeat
Distributed systems