Long Polling: What It Is, How It Works, and Where It’s Used

Author: IT Sectr Published: 2026-06-02 Reading time: 8 min

Long Polling is a client-server interaction technique where the server holds an HTTP request open until new data becomes available or a timeout expires. Unlike periodic polling, the server does not return an empty response immediately but waits for an event to occur before sending data to the client. According to MDN Web Docs, 2024, Long Polling remains a popular solution for real-time applications where WebSocket is unavailable or excessive.

Key Takeaways

  • Long Polling — a technique where the server holds an HTTP request until data becomes available and only then sends a response to the client.
  • Mechanism — based on long HTTP connections: the client sends a request, the server does not respond immediately but waits for an event or timeout.
  • Difference from Short Polling is that the server initiates data transmission, and the client does not poll the server on a timer.
  • Use cases include chats, notifications, activity feeds, and real-time monitoring systems.
  • Limitation — high server load with a large number of concurrent connections due to keeping open requests.

What is Long Polling

Long Polling is a communication pattern in a client-server architecture where a client initiates an HTTP request, and the server delays sending a response until new data becomes available or a specified timeout expires. After receiving the response, the client immediately sends the next request, creating the effect of a continuous connection.

The Long Polling technique emerged as an evolutionary development of Short Polling to reduce the number of empty HTTP requests. In traditional polling, the client sends requests every N seconds, and the server responds even when there is no new data. In Long Polling, the server uses a connection holding mechanism, which dramatically reduces useless traffic.

The History of Long Polling

Before the advent of WebSocket in 2011, Long Polling was the primary method for real-time communication on the web. Companies such as Facebook and Gmail used this technique for their chats and notifications in the early 2010s. According to High Performance Browser Networking (Grigorik, 2013), Long Polling handled up to 95% of all real-time connections in major web applications of that period.

Basic Principle of Long Polling

A client sends a standard HTTP request to the server. Upon receiving the request, the server does not return a response immediately — it places the request in a waiting queue. When an event occurs on the server (a new message, data change), the server forms a response and sends it to the client. Upon receiving the response, the client immediately creates a new Long Polling request, and the cycle repeats.

How Long Polling Works

Long Polling works according to the following sequence of steps. The client sends an HTTP GET request to a server endpoint. Upon receiving the request, the server checks for new data in the event queue. If there is no data, the server holds the request in a waiting state, not sending a response immediately. The holding mechanism depends on the server implementation — most often asynchronous processing with callbacks or event-driven architecture is used.

When an event occurs on the server side (for example, a user sent a message in a chat), the server forms an HTTP response with a body containing this data and terminates the connection. The client receives the response, processes the data, and immediately initiates a new request. If no data appears during the waiting period, the server sends an empty response after the timeout expires, and the client also re-establishes the connection. The timeout is usually 30–60 seconds for a balance between load and latency.

Timeouts and Connection Management

A key configuration parameter for Long Polling is the waiting timeout. A timeout that is too short (less than 10 seconds) leads to an increase in the number of requests, bringing the technique closer to Short Polling. A timeout that is too long (more than 120 seconds) may cause connection breaks by intermediate proxies and load balancers. The recommended value for most scenarios is 30–45 seconds.

Handling Multiple Events

If multiple events occur on the server during a single Long Polling request, the server must transmit them all in one response or organize an event queue on the client side. For this purpose, event buffering is used: the server accumulates events that occurred during the holding time of the request and transmits them as an array of data in the response body.

Long Polling Implementation Example in JavaScript

Let’s look at a simple Long Polling implementation on the client side using the modern Fetch API. The client function sends a request and recursively calls itself after receiving a response.

js
async function longPoll(url) {
    try {
        const response = await fetch(url);
        const data = await response.json();

        handleData(data);
        longPoll(url);
    } catch (error) {
        console.error("Long Polling error", error);
        setTimeout(() => longPoll(url), 3000);
    }
}

function handleData(data) {
    if (data.events && data.events.length > 0) {
        data.events.forEach(event => {
            console.log("New event:", event);
        });
    }
}

longPoll("/api/events");

This code creates an infinite Long Polling loop: after receiving a response, the function immediately sends a new request. In case of a connection error, a three-second delay is set before retrying to avoid avalanche load on the server.

Server Implementation on Node.js

On the server side, it is necessary to hold the request until an event occurs or a timeout expires. An implementation example using EventEmitter in Node.js demonstrates this mechanism.

js
const express = require("express");
const EventEmitter = require("events");
const app = express();

const eventBus = new EventEmitter();

app.get("/api/events", (req, res) => {
    const timeout = setTimeout(() => {
        res.json({ events: [] });
    }, 30000);

    eventBus.once("new-event", (data) => {
        clearTimeout(timeout);
        res.json({ events: [data] });
    });
});

app.post("/api/events", (req, res) => {
    eventBus.emit("new-event", req.body);
    res.send({ status: "ok" });
});

app.listen(3000);

The server part uses EventEmitter to notify waiting Long Polling connections when new data appears. Upon reaching the 30-second timeout, the server returns an empty array of events, and the client creates a new request.

When to Use Long Polling

Long Polling is used in scenarios where real-time data delivery is required but using WebSocket is impossible due to technical or infrastructural reasons. The most common cases are corporate proxies and firewalls that block WebSocket connections, as well as environments with limited protocol support on the server side.

  • Chats and messengers — Long Polling provides message delivery in web versions of messengers operating over HTTP without WebSocket.
  • Dashboard panels — real-time systems for DevOps metrics, logs, and alerts where data timeliness with 1–5 second delay is important.
  • Notifications — push-like delivery of alerts in the browser without using Service Workers and Push API.
  • Activity feeds — social networks and news feeds with automatic content updates when new posts appear.
  • Collaboration — Google Docs-like editors with basic synchronization of changes between users.

The key factor in choosing Long Polling is backward compatibility. All HTTP clients and servers support this method, making it a universal solution for real-time functionality without additional dependencies. According to HTTP Archive (2024), about 8% of all websites continue to use Long Polling for basic real-time functionality.

Long Polling vs Short Polling

Long Polling and Short Polling solve the same problem — data delivery from server to client — but fundamentally differ in mechanism and efficiency. Short Polling uses a fixed polling interval where the client sends HTTP requests at equal time intervals regardless of whether new data has appeared on the server.

CharacteristicLong PollingShort Polling
Response initiationServer sends data on eventServer responds to each client request
Delivery latencyMinimal, up to 1 secondDepends on polling interval, 3–60 seconds
Number of requests1 request per event or timeoutN requests per unit of time (fixed)
Idle trafficLow (one open request)High (requests every N seconds)
Server loadHolding connectionsProcessing frequent requests
Implementation complexityMedium (asynchronous processing)Low (regular HTTP requests)

Short Polling is simpler to implement but creates significantly more load on the server and network with the same data update frequency. If a latency of less than 5 seconds is required, Short Polling generates dozens of requests per minute, while Long Polling uses one request per event or timeout. For applications with infrequent events, Long Polling is orders of magnitude more traffic-efficient.

Long Polling vs WebSocket

WebSocket is a full-fledged bidirectional real-time protocol operating over TCP after an initial HTTP handshake. Unlike Long Polling, WebSocket establishes a single persistent connection and allows the server to send data to the client at any time without creating a new HTTP request.

The choice between Long Polling and WebSocket depends on several factors. Compatibility: Long Polling works through any proxies and firewalls, while WebSocket may be blocked by corporate networks. Performance: WebSocket has lower overhead (2 bytes per frame versus full HTTP headers), which is critical at high message frequency. Scalability: Long Polling requires more server-side resources due to holding many connections, while WebSocket uses a fixed connection per session.

  • Long Polling — the best choice for applications with low event frequency (1–10 events per minute), limited infrastructure, or the need to support older browsers.
  • WebSocket — the optimal solution for high-load real-time applications (stock exchange data, online games, collaborative editors) with hundreds of messages per second.
  • Hybrid approach — some applications use Long Polling as a fallback for clients that do not support WebSocket, with automatic protocol switching.

According to Mozilla Developer Network (2024), WebSocket is supported by all modern browsers since versions 2011–2015, but corporate proxies (e.g., Symantec Blue Coat) continue to block it in 15–20% of corporate networks, which keeps Long Polling relevant as a fallback solution.

Frequently Asked Questions

What is Long Polling in simple terms?

Long Polling is when a client asks the server: “respond when new data becomes available,” and the server keeps the connection open, waiting for an event. As soon as data appears, the server responds, and the client immediately asks the same question again.

How is Long Polling different from Short Polling?

With Short Polling, the client asks the server every N seconds whether there is data, even if there isn’t. With Long Polling, the client asks once, and the server only responds when data actually becomes available. Long Polling creates fewer empty requests and reduces network load.

When should I use Long Polling instead of WebSocket?

Long Polling should be used when WebSocket is unavailable: in corporate networks that block non-HTTP protocols, when backward compatibility with older browsers is needed, or when there are hosting-side limitations. WebSocket is more efficient for high-frequency data exchange.

What timeout should I set for Long Polling?

The recommended Long Polling timeout is 30–45 seconds. A lower value (10–15 seconds) increases the number of requests, while a higher value (60+ seconds) risks connection breaks by intermediate load balancers. The timeout value depends on the network architecture and latency requirements.

What are the disadvantages of Long Polling?

The main disadvantages of Long Polling are high memory consumption on the server when holding thousands of connections, difficulty in horizontal scaling (requires a centralized event queue), and the lack of true bidirectional communication — separate POST requests are needed to send data to the server.

Summary

  • Long Polling — a real-time data transfer technique where the server holds an HTTP request until an event occurs and only then sends a response to the client.
  • Mechanism — based on asynchronous HTTP connection holding: the server does not return an empty response but waits for data or a 30–45 second timeout.
  • Advantage — compatibility with all HTTP infrastructure: proxies, load balancers, and firewalls do not block Long Polling unlike WebSocket.
  • Disadvantage — resource-intensive on the server side: each connection consumes memory and requires asynchronous processing even when there are no events.
  • Use cases — chats, notifications, dashboard panels, activity feeds, and collaborative editors with low update frequency.
  • Comparison — more efficient than Short Polling for infrequent events, but inferior to WebSocket in performance and scalability for high-frequency scenarios.
  • Recommendation — use Long Polling as a fallback when WebSocket is unavailable or for simple real-time scenarios with low event frequency.

We will develop a mobile application turnkey

IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.

Discuss the project

Read also