Long Polling
Subject: Computer and Technology noun /ˈlɔːŋ ˈpoʊ.lɪŋ/ 1 definition
- computer-networking
- web-development
- real-time-communication
- distributed-systems
-
Definition (noun)
Entry #322 · UpdatedLong Polling is a client-server communication pattern built on the request-response model—most commonly HTTP—that simulates low-latency server push without requiring a persistent streaming protocol. Rather than replying immediately when no updates exist, the server holds the client's request open until new data becomes available or a configured timeout period elapses. Once the server transmits the response payload or a timeout status, the client processes the result and immediately dispatches a new request to await subsequent events. By deferring responses until state changes occur, long polling reduces empty network round trips compared to short polling and operates reliably through restrictive proxies and firewalls, though repeated request headers and held server connections create higher overhead than WebSockets or Server-Sent Events at high message rates.
Common Forms
Fetch and XHR Long Polling: Web clients issue sequential
fetch()orXMLHttpRequestrequests over HTTP keep-alive connections, holding each request open until an update payload or timeout response returns.Cursor-Based Long Polling: Clients attach an offset, event ID, or timestamp parameter (such as
?since=1042) so the server can immediately flush events missed between cycles or block until a newer record arrives.Message-Queue Long Polling: Distributed brokers (such as Amazon SQS using
WaitTimeSeconds) suspend consumerReceiveMessagecalls until at least one message enters the queue or the wait window expires, eliminating empty polling requests.Fallback Transport Long Polling: Real-time messaging libraries such as Socket.IO establish connections over HTTP long polling before upgrading to WebSockets, preserving message delivery when restrictive proxies block
Upgradehandshakes.
Example
A web chat client issues an HTTP
GET /messages?after_id=418&timeout=25request viafetch(), and the API server holds the request open rather than immediately returning an empty list. When a new message arrives 14 seconds later, the server responds with200 OKand{"id":419,"text":"Deploy complete"}, prompting the client to append the message and immediately open a new request withafter_id=419; if 25 seconds pass without activity, the server returns204 No Contentand the client restarts the cycle.