Topic 39

Polling: Are We There Yet?

Events

The transport office has a new question, and it is a different shape from every question so far. Not "how many bikes are at Old Market" — that one has an answer right now. This one is "tell me when ride rd_7c29 ends", and it has no answer yet. Bike bk_0412 is out somewhere in Riverport, and the rebalancing crew's afternoon depends on when it docks.

With everything the book has taught so far, there is exactly one way to find out: ask, wait, and ask again until the answer changes. That is called polling, and it is the request/response model of Chapter 1 stretched over time. It is honest work with an honest cost, and knowing that cost is what makes the next page land.

Forty asks, one that mattered
GET the ridestatus: active
Wait 60 secondsthe dial you set
Ask again · ×39still active
The answer changesstatus: completed

The Pattern: Ask, Wait, Ask Again

The whole technique is one command on a repeat. Ask the ride's address for its current state, read the status field out of the JSON that comes back, and decide. If it says active, the ride is still running and there is nothing to do but wait and ask again. If it says completed, the news has arrived and the loop stops.

One poll: the request, and the answer thirty-nine times out of forty
curl -H "Authorization: Bearer tnd_live_..." \
  "https://api.tandem.example/v1/rides/rd_7c29"

{"id": "rd_7c29", "bike_id": "bk_0412", "status": "active",
 "started_at": "2026-08-27T17:12:41Z", "end_station_id": null}

Nothing on this page is new. It is the Chapter 3 command, the Chapter 4 habit of reading one field out of an object, and a clock. That is polling's genuine virtue and the reason it is everywhere: it needs no new machinery, no new permissions, and no cooperation from the provider beyond the endpoint that already exists.

The everyday version is the voice from the back seat of a car. "Are we there yet?" does produce the information — eventually, accurately, and at the price of asking every ninety seconds for three hours. The driver would much rather promise to announce the arrival, and that promise is the next page.

The Two Dials

Polling has exactly one setting, the interval between asks, and it moves two things in opposite directions. Ask often and the news reaches you sooner, at the cost of more requests. Ask rarely and you spend almost nothing, at the cost of hearing late.

Put numbers on it and the shape is obvious. Polling one ride every ten seconds means you learn of its end within ten seconds, and it costs six requests a minute. Polling it every ten minutes costs a tenth of a request a minute, and the news can sit unheard for up to ten minutes. There is no setting called instant and free, and picking where on that line you want to sit is the design work.

Chapter 8 already handed you the wall this runs into. Tandem allows sixty requests a minute per key. Watching one ride every ten seconds uses a tenth of that. Watching ten rides at once, at the same speed, uses all of it — and leaves nothing for the station sweep the report actually needs.

The Arithmetic of Mostly-No

Here is the number that makes the case. A ride that lasts forty minutes, polled once a minute, costs forty requests — and thirty-nine of them answer "not yet". One request in forty carried news. The other thirty-nine were complete, correct, well-formed exchanges that told the office something it already knew.

Now multiply by Riverport. Watching a dozen rides at the ten-second pace would overrun the whole budget by itself; even at once a minute, a fifth of it goes to hearing "not yet", and the fraction gets worse the rarer the event is. That is the signature of polling done wrong: not that it fails, but that the ratio of asks to news quietly becomes absurd while everything still appears to work.

When Polling Is Simply Right

None of which makes polling a mistake. It is the correct tool surprisingly often, and reaching for something cleverer when it is not needed costs more than the requests would have.

Poll for one-off checks, where you look once or twice and stop — the ambiguous POST from Chapter 7 was settled by exactly one such look. Poll for anything on a slow human rhythm: a spreadsheet refreshed hourly, a dashboard that nobody watches between meetings, the Thursday report itself. Chapter 8's freshness question does the deciding for you: how old may this answer be? If the honest answer is "an hour", then asking once an hour is not a compromise, it is the right size of ask.

The sin is not polling. The sin is polling fast for news that arrives rarely, which is precisely the case the next page exists to solve.

Common Confusions
  • "Polling is bad practice." It is a trade: simplicity and control bought with requests and staleness. At the right frequency for the right data it is the boring, professional, correct choice, and a great deal of working software does nothing else.
  • "Polling faster gets me the event sooner." It narrows the window you might miss it in, at a linear cost in requests, and under a sixty-a-minute ceiling "faster" hits a hard wall. The ride still ends when it ends; only your ignorance of it gets shorter.
  • "The server knows I am waiting and will hurry." Each poll is a stateless stranger, exactly as Chapter 1 described. The server neither remembers your last ask nor anticipates your next, and that indifference is the thing the next page fixes.
Why It Matters
  • How often should this thing check? is a real decision people make at work about dashboards, monitors and integrations, usually by guessing. You can now do the arithmetic on a napkin: interval, requests per minute, budget, and how stale is tolerable.
  • Feeling the cost of polling in your own hands is the only way the next page reads as relief rather than as magic. Mechanisms that arrive before their problem never stick.

Knowledge Check

What does polling actually consist of?

  • Sending the same request on a timer until the answer changes
  • Sending one request that the server holds open until news arrives
  • Registering an address that the provider will send the news to
  • Downloading a log of everything that happened since yesterday

A forty-minute ride is polled once a minute. What does that cost, and what does it buy?

  • Forty requests, but only the last one counts against the rate limit
  • Forty requests, thirty-nine of which answer that nothing has happened
  • One request, because the server answers again when the ride ends
  • Forty requests, and the end of the ride known the instant it happens

The office halves its polling interval from sixty seconds to thirty. What actually changes?

  • Rides finish sooner because the server is prompted more often
  • The requests double but stop counting toward the key's budget
  • The news is fresher and the requests double
  • The delay disappears entirely and the cost stays the same

Vera needs station counts for a report she assembles every Thursday morning. What is the right approach?

  • Poll every few seconds so the numbers are as fresh as possible
  • Ask once, on Thursday morning, when she needs the numbers
  • Avoid polling entirely, since it is never the professional option
  • Ask Tandem to send the station counts to her automatically

You got correct