SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
  • Long Polling
  • Server-Sent Events (SSE)
  • WebSockets
  • Webhooks
  • WebRTC
  • Short Polling
  • Push Notifications
  • MQTT
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/APIs and Communication/Real-Time Communication

Short Polling

Ask again and again on a timer. Simple, but wasteful. The baseline to compare the others with.

⏱ 10 min readBeginnerHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

Short polling means the client asks the server “Is there anything new?” on a fixed timer, for example every 5 seconds, and the server answers at once, even if the answer is “no”.

  • It is the simplest way to get fresh data. It works over plain HTTP, everywhere.
  • It is wasteful when news is rare: most answers are empty.
  • News can be late by up to the polling gap.
  • It is the baseline to compare long polling, SSE and WebSockets against.

02Concept: What is it?

HTTP is request and response: the client always speaks first. So a page that wants to know about changes has to keep asking. Short polling does this with a timer: ask, wait N seconds, ask again.

The two numbers that matter

Load on the server is users ÷ gap. With 10,000 users and a 5-second gap, the server handles 2,000 requests every second, whether or not anything changed. Delay for a user is anything from zero up to the gap, half the gap on average. A smaller gap means fresher data but more load. A bigger gap saves load but makes news late.

Short polling over time
  1. 1
    t = 0 s: client asks
    Server: nothing new.
  2. 2
    t = 5 s: client asks again
    Server: nothing new.
  3. 3
    t = 7 s: news happens on the server
    No one is told. The server cannot start talking.
  4. 4
    t = 10 s: client asks again
    Server: here is the news. It arrived 3 s late.
Most of the questions get the answer 'nothing new'. The news is only seen at the next poll.
🧠Remember
The cost of short polling is paid all the time, by every user, even when nothing happens. That is why it does not scale well for rare events.

03Real-Life Example

🍵Checking the mailbox
You expect a parcel. Every 10 minutes you walk to the front door and look in the mailbox. Most times it is empty. Sometimes the parcel came 9 minutes ago and has been sitting there. If you check every minute you find it sooner, but you spend your whole day walking to the door. A doorbell (a push from the delivery person) would be better, but you do not always have one.
Checking the mailbox
Short polling
Walking to the door
Sending a request
An empty mailbox
An empty answer (nothing new)
How often you walk
The polling gap
Finding a parcel that came earlier
Receiving news that is already old
Many neighbours all checking
Many users polling the same server
A doorbell
SSE, WebSockets or push, where the server speaks first
Choosing the gap
Gap of 1 secondvery fresh, very heavy
Gap of 10 secondsbalanced
Gap of 60 secondslight, but late
Server load (relative, illustrative)

04Why Do We Need It?

If short polling is wasteful, why learn it? Because it is the right answer more often than people think, and it is the yardstick for every other option.

🧰Dead simple
A timer and a normal GET request. No special server, no open connections, no new protocol.
🌍Works everywhere
Firewalls, proxies and old browsers all allow plain HTTP.
🗑️Stateless
The server holds nothing between requests, so any server behind a load balancer can answer.
⏱️Fine for slow news
If a few seconds of delay is fine, a 30-second gap costs very little.
📉Easy to reason about
Load = users ÷ gap. You can predict it and plan capacity for it.
🧪A baseline
To justify the extra work of WebSockets, first show that polling is too heavy or too slow.
Short polling is cheap to build and expensive to run. Use it when events are frequent enough, or delay is acceptable.

05Where Do We Use It?

⏳Job status
“Is my export ready?” The page asks every few seconds until the job is done, then stops.
💳Payment confirmation
After redirecting back from a payment page, the app polls the order status for a short time.
📊Slow dashboards
A graph that refreshes every 30 or 60 seconds does not need a live connection.
📦Order tracking
A tracking page that checks for a new location now and then.
🔌Simple integrations
A script that checks another system for changes on a schedule, where no webhook exists.
🧯Fallback
When WebSockets or SSE are blocked, an app can fall back to polling.

06Types / Parts / How It Works

How a polling loop works

  1. 1
    Set a timer
    For example every 5 seconds. Pause it when the tab is hidden.
  2. 2
    Send a GET
    Include what you already have: a version, a timestamp or the last event id.
  3. 3
    Server answers immediately
    New data with 200, or 304 Not Modified (or 204 No Content) if nothing changed.
  4. 4
    Client updates the page
    Only if there was news.
  5. 5
    Wait, then ask again
    Wait for the gap. Stop when the job is finished.

Ways to make polling cheaper

IdeaHow it helps
A longer gapLoad falls in proportion, but news is later
ETag and 304 Not ModifiedAn unchanged answer is tiny, so bandwidth falls a lot, though the request still happens
Ask for changes since XThe answer only carries new items, not the whole list
Pause when the tab is hiddenNobody is looking, so no need to ask
Backoff while nothing changesAsk less often the longer the quiet lasts, and speed up when news arrives
JitterAdd a random bit to each timer, so thousands of clients do not all hit at the same second

Polling compared with the other ways

MethodWho starts talkingDelayWasteComplexity
Short pollingClient, on a timerUp to the gapHigh if news is rareLowest
Long PollingClient, server holds the answerAlmost noneLowMedium
Server-Sent Events (SSE)Server pushes over one open connectionAlmost noneLowMedium
WebSocketsEither side, over one open connectionAlmost noneLowHigher
JavaScript (general idea)
let lastEtag = null;
async function poll() {
  const res = await fetch("/status", { headers: lastEtag ? { "If-None-Match": lastEtag } : {} });
  if (res.status === 200) {
    lastEtag = res.headers.get("ETag");
    show(await res.json());
  }                                     // 304 means "no change", so do nothing
}
const id = setInterval(poll, 5000);     // clearInterval(id) when the job is done
VisualizerPolling gap, load and wasted answersChange the number of users and the gap. Then make news rare or frequent and watch how many answers are empty.
Can the server answer 'nothing changed' cheaply?
Requests per second the server must handle, for different polling gaps (your setting is highlighted)
1 s
10k/s
2 s
5.0k/s
5 s
2.0k/s
10 s
1.0k/s
30 s
333/s
60 s
167/s
Of every 100 answers at your setting
green = has news (0.8)grey = empty (99.2)
Requests / second
2.0k
users ÷ gap
Empty answers
99.2%
wasted work
Average delay
2.5 s
worst case 5 s
Useful answers / s
17
answers with news
Data sent
4.00 MB/s
illustrative sizes
99.2% of the answers are "nothing new". The server does about 2.0k requests every second, and almost all of that work is wasted.

Exact arithmetic, no random numbers. Each user asks once per gap, so load = users ÷ gap. The share of answers that carry news is 1 − e−rate × gap, where news arrives at an average rate per user. A full answer is 2,000 bytes and a 304 answer is 300 bytes: both are illustrative sizes.

07How to Use It / Steps / Implementation

Polling without hurting your servers

  1. Work out the load first. Users ÷ gap. If that number scares you, change the design before you ship.
  2. Choose the gap from what users need, not from habit. A job status page may be fine at 3 seconds, a daily report at 60.
  3. Use ETag or a version. Return 304 when nothing changed, so the answer is a few hundred bytes.
  4. Make the status endpoint cheap. Read from a cache, not from a heavy query.
  5. Add backoff and jitter. Slow down during quiet times. Spread timers so there are no synchronised waves.
  6. Stop when done. A job page should stop polling as soon as the job is finished, failed or the tab is closed.
  7. Respect Retry-After and rate limits. If the server says “slow down”, slow down.
  8. Move on when it hurts. If load or delay are too high, switch to long polling, SSE or WebSockets.
💡Do the maths in one line
100,000 users × one request every 5 seconds = 20,000 requests per second, even if no one has any news. That is the number to compare with a held-open connection.

08Key Terms to Know

TermMeaning in easy words
PollingAsking a server again and again whether something changed
Short pollingPolling on a fixed timer, where the server answers at once
Polling gap (interval)The time between two requests from the same client
Empty responseAn answer that says nothing changed, which costs work for no value
ETagA tag for a version of a resource, used to ask 'has it changed?'
304 Not ModifiedA tiny answer meaning 'what you have is still current'
BackoffWaiting longer between requests when nothing is happening
JitterA little randomness added to timers so clients do not line up
Thundering herdMany clients acting at the same moment, causing a load spike
Long pollingThe server holds the request open until it has news
BaselineThe simple option you compare other options against

09Pros, Cons and Trade-offs

✅ Pros
  • Very simple to build and to debug
  • Works with any HTTP stack, proxy and firewall
  • Stateless, so it scales by adding servers
  • Predictable load: users ÷ gap
  • Good enough when news is frequent or delay is acceptable
⚠️ Cons
  • Many empty answers when news is rare
  • News is late by up to the gap (half on average)
  • Load grows with users even when nothing happens
  • A short gap multiplies server cost
  • Synchronised timers can cause spikes

Trade-offs

ChoiceWe gainWe lose
Shorter gapFresher dataMore load and more empty answers
Longer gapMuch less loadNews waits longer
ETag / 304Small answers when unchangedA little more logic on the server
Backoff when quietSavings during idle timesSlower to notice the first news after a quiet period
Switch to push (SSE, WebSockets)Low delay and low wasteOpen connections and more moving parts

10Common Problems and Mistakes

Common mistakes

  1. Polling forever. A page keeps asking after the job is done, or in a hidden tab.
  2. Too short a gap. A one-second gap for 100,000 users is 100,000 requests per second.
  3. Heavy queries on a polled endpoint. The same expensive query runs thousands of times a second.
  4. All timers in step. After a restart or a deploy, every client asks in the same second.
  5. No error backoff. When the server struggles, clients retry faster and make it worse.
  6. Returning the full body every time. Without ETag or “since”, bandwidth is wasted.
  7. Missing events. If the answer only says “the latest state”, changes between two polls are lost. Ask for changes since a position when each event matters.

Things to watch

📈Requests per second
Track it against users. It should move with users ÷ gap.
🗑️Empty-answer ratio
A ratio near 100% is a sign to lengthen the gap or switch method.
🌊Waves of traffic
Look for spikes at round times. They mean timers are in step.
🔋Mobile cost
Frequent polling drains batteries and data plans.

11Real-World Examples

📤Export and report jobs
Pages that build a file in the background and poll until a download link is ready.
🏗️Build and deploy status
Many tools show job progress by asking a status endpoint every few seconds.
🛒Checkout results
After a redirect from a payment page, the store checks the order status for a short time.
📰Slow-moving feeds
A page showing data that changes every minute can poll with a long gap.
🧯Fallback transport
Real-time libraries often fall back to polling when nothing else works.
📝Note
The numbers in the visualizer are examples, not benchmarks. Measure your own traffic before you choose a gap.

12Related Topics to Read Next

Long Polling→

The next step: the server holds the answer until it has news.

Server-Sent Events (SSE)→

One open connection that the server pushes events through.

WebSockets→

A two-way connection for chat, games and live data.

Webhooks→

Let the other system call you when something changes.

Rate Limiting→

Protects a status endpoint from clients that poll too fast.

Retries with Backoff→

The same idea of waiting longer between attempts.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • ✔What: the client asks on a timer. The server answers at once.
  • ✔Load: users ÷ gap requests per second, news or not.
  • ✔Delay: up to the gap, half the gap on average.
  • ✔Waste: most answers are empty when news is rare.
  • ✔Cheaper: ETag and 304, “changes since X”, backoff, jitter, pause in hidden tabs.
  • ✔Good for: job status, slow dashboards, payment confirmation, fallback.
  • ✔Move on to: long polling, SSE, WebSockets or webhooks when it is too heavy or too slow.
  • ✔One line: “Easy to build, costly to run: pay for it all the time, even when nothing happens.”
← Previous
WebRTC
Next →
Push Notifications