liveBook · Manning

Polling

As explained in The Art of Code

A communication technique in which a program repeatedly requests an endpoint to check for changes.

Polling repeatedly calls an endpoint to check for changes. It is straightforward, but fixed-interval requests can waste network and server resources when nothing has changed. section 8.4.4

Choose polling deliberately:

  • Use a modest interval when updates are rare and simplicity matters. section 8.4.4
  • Treat the polling rate as a resource decision: polling every five seconds instead of every five minutes creates 59 extra requests per five-minute window. section 8.4.4
  • Consider WebSockets or Server-Sent Events when updates are frequent, while accounting for their open connections and server-resource costs. section 8.4.4

Dashboard refresh

A weather or financial dashboard can contact the backend at fixed intervals and ask, “Anything new?” If changes are infrequent, lengthening the interval may avoid many empty responses without requiring a more complex push mechanism. section 8.4.4

How The Art of Code covers it

How deep it goes
Defines polling, illustrates fixed intervals and wasted requests, and stops short of implementation code.
Examples
Uses weather or financial dashboards and a five-second-versus-five-minute interval comparison.
What you can do after
Evaluate polling intervals and choose between polling and push-based updates for a use case.
How it connects
Connects polling with HTTP caching, offline-first design, WebSockets, and Server-Sent Events.

Also explained in

Compare how 9 books explain polling →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Art of Code. The section links point to the parts of the book it draws on.