Long Polling
Definition
Long polling is a way to push updates to a client over plain HTTP. The client sends a request and the server holds the connection open until it has data or hits a timeout, then responds; the client immediately reconnects and waits again. It works everywhere HTTP works, including through restrictive firewalls and proxies, which makes it a solid fallback when WebSockets or server-sent events are not available.
Key Takeaways
- The server holds the request open until data is ready, so the client gets updates without constant polling.
- It works anywhere HTTP does, even through proxies and firewalls that block WebSockets.
- Each cycle is a fresh HTTP request, so it carries more header overhead than a persistent connection.
- Best for infrequent updates (less than one per second) or serverless platforms where holding sockets is hard.
How It Works
- The client sends an HTTP request asking for new data.
- The server holds the request open instead of replying immediately.
- When data arrives or a timeout is reached, the server responds.
- The client processes the response and immediately opens a new request to keep listening.
Where It Is Used
- Many chat and notification systems fall back to long polling when WebSockets are blocked.
- Older real-time libraries like the early Socket.IO transports used long polling under the hood.
- It is common on serverless stacks where long-lived socket connections are impractical.