What Is Long Polling?

Long polling is a technique where the client makes a request that the server holds open until new data is available (or a timeout occurs), then the client im...

Published October 9, 2026

Long polling is a technique where the client sends a request and the server holds it open until new data is available (or a timeout), then the client immediately asks again. It approximates real-time updates over plain HTTP.

The concept

Unlike regular polling every few seconds, the request waits on the server, so updates arrive quickly without constant empty responses.

It works through proxies and old browsers, but ties up a connection per client and has more overhead than WebSockets.

Hold the request open

  1. Client sends GET /updates
  2. Server waits until an event happens
  3. Server responds with the data
  4. Client immediately sends the next request

Practical examples

Client loop

async function poll() {
  try {
    const r = await fetch('/updates?since=' + last)
    if (r.status === 200) handle(await r.json())
  } catch {}
  poll()
}
poll()

Server holding the request

app.get('/updates', (req, res) => {
  const t = setTimeout(() => res.sendStatus(204), 25000)
  bus.once('event', d => { clearTimeout(t); res.json(d) })
})

Better today

Prefer SSE or WebSocket when you control both ends.

SSE → one-way push · WebSocket → two-way

Common mistakes

  • Timeouts shorter than the proxy's idle timeout.
  • No back-off after errors, hammering the server.
  • Missing events between requests (track a cursor).

Key takeaways

  • Request waits until data exists.
  • Works everywhere over HTTP.
  • SSE/WebSocket are more efficient.

FAQ

Is long polling still used?

As a fallback in libraries like Socket.IO.

How long should the server wait?

Typically 20–60 seconds, under proxy timeouts.

More General articles