Ask again and again on a timer. Simple, but wasteful. The baseline to compare the others with.
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”.
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.
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.
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.
| Idea | How it helps |
|---|---|
| A longer gap | Load falls in proportion, but news is later |
| ETag and 304 Not Modified | An unchanged answer is tiny, so bandwidth falls a lot, though the request still happens |
| Ask for changes since X | The answer only carries new items, not the whole list |
| Pause when the tab is hidden | Nobody is looking, so no need to ask |
| Backoff while nothing changes | Ask less often the longer the quiet lasts, and speed up when news arrives |
| Jitter | Add a random bit to each timer, so thousands of clients do not all hit at the same second |
| Method | Who starts talking | Delay | Waste | Complexity |
|---|---|---|---|---|
| Short polling | Client, on a timer | Up to the gap | High if news is rare | Lowest |
| Long Polling | Client, server holds the answer | Almost none | Low | Medium |
| Server-Sent Events (SSE) | Server pushes over one open connection | Almost none | Low | Medium |
| WebSockets | Either side, over one open connection | Almost none | Low | Higher |
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 doneExact 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.
| Term | Meaning in easy words |
|---|---|
| Polling | Asking a server again and again whether something changed |
| Short polling | Polling on a fixed timer, where the server answers at once |
| Polling gap (interval) | The time between two requests from the same client |
| Empty response | An answer that says nothing changed, which costs work for no value |
| ETag | A tag for a version of a resource, used to ask 'has it changed?' |
| 304 Not Modified | A tiny answer meaning 'what you have is still current' |
| Backoff | Waiting longer between requests when nothing is happening |
| Jitter | A little randomness added to timers so clients do not line up |
| Thundering herd | Many clients acting at the same moment, causing a load spike |
| Long polling | The server holds the request open until it has news |
| Baseline | The simple option you compare other options against |
| Choice | We gain | We lose |
|---|---|---|
| Shorter gap | Fresher data | More load and more empty answers |
| Longer gap | Much less load | News waits longer |
| ETag / 304 | Small answers when unchanged | A little more logic on the server |
| Backoff when quiet | Savings during idle times | Slower to notice the first news after a quiet period |
| Switch to push (SSE, WebSockets) | Low delay and low waste | Open connections and more moving parts |