Comparisons

Long Polling vs WebSockets

Long polling fakes real-time over ordinary HTTP by holding requests open; WebSockets keep one persistent connection for true low-latency, two-way messaging.

2 min read·8 sections
Open the interactive version → diagrams, practice & more

Overview

Before WebSockets, the way to get near-real-time updates was long polling: the client makes an HTTP request the server holds open until it has data, then the client immediately re-requests. It works through any firewall or proxy and needs no special protocol, but every message costs a fresh round trip and a connection setup. WebSockets replace that with one upgraded TCP connection both sides can push over instantly — far lower latency and overhead for chatty, bidirectional traffic — at the cost of stateful connections your infrastructure must support.

Long Polling vs WebSockets: key differences

Long PollingWebSockets
LatencyA round trip per messageNear-instant push
ConnectionRepeated short HTTP requestsOne long-lived socket
OverheadHigh (headers + reconnect each time)Low after handshake
CompatibilityWorks everywhere, no upgradeNeeds WS-aware proxies/LBs
DirectionEffectively server → clientFull duplex

When to use Long Polling

Legacy environments or restrictive networks where WebSockets are blocked, low-frequency updates, or when you want the simplest possible HTTP-only fallback.

When to use WebSockets

High-frequency, low-latency, two-way messaging — chat, multiplayer, live collaboration — where the persistent connection pays for itself.

Verdict

Use WebSockets for genuine real-time, bidirectional traffic; they are more efficient and lower latency. Keep long polling as a fallback for clients or networks that can't hold a WebSocket. Many libraries (e.g. Socket.IO) negotiate WebSockets first and fall back to long polling automatically.

Common questions

Is long polling still used?

Yes — mainly as a fallback when WebSockets or SSE are unavailable (old browsers, strict corporate proxies). For new real-time features, WebSockets or SSE are preferred; long polling is the compatibility safety net.

Why are WebSockets more efficient than long polling?

Long polling reopens a connection and resends HTTP headers for every message and incurs a round trip; WebSockets keep one connection open and push small framed messages with minimal overhead.

Part of Comparisons on SystemLore — system design explained with 148 deep topics, interactive diagrams, and a build-it-yourself game. Browse the glossary and "X vs Y" comparisons, or build this one →