Archprimer
TradeoffIntermediate 7 min read

Polling vs WebSockets

Polling repeatedly asks the server for updates over stateless HTTP; WebSockets hold one persistent bidirectional connection for real-time push. Simplicity vs latency.

realtimehttpwebsocketspolling

By Ratish Jain · Updated

Diagram with 5 components: Client, HTTP Endpoint, WS Server, Data Source, Event Bus. Connections: Client → HTTP Endpoint (GET /new?); Client → WS Server (upgrade); HTTP Endpoint → Data Source (check); Event Bus → WS Server (push).
ClientGatewayServiceDatabaseQueue
Repeated request-response versus one persistent duplex channel.

The Decision

The question is how a client learns about new data. Polling keeps HTTP's simple request-response model: the client repeatedly asks "anything new?". Short polling fires on a timer (wasting requests when nothing changed), while long polling holds the request open until data arrives or it times out, reducing chatter.

WebSockets upgrade a single HTTP connection into a persistent, full-duplex channel so the server can push instantly and the client can send at any time — ideal for chat, live feeds, and multiplayer.

So it depends on how real-time and bidirectional you need to be, weighed against the simplicity and statelessness of plain HTTP.

Side by Side

PollingWebSockets
ConnectionNew request each timeOne persistent connection
DirectionClient pulls onlyFull-duplex push/pull
LatencyUp to poll intervalNear-instant
Server loadWasted empty requestsMany open sockets to hold
Infra fitWorks with any HTTP/LBNeeds sticky/aware LB, scaling
ComplexityVery simpleReconnects, heartbeats, state
Best forInfrequent updatesChat, live dashboards, games

WebSockets Strengths & Weaknesses

Pros
  • True real-time, low-latency, bidirectional messaging
  • No repeated HTTP overhead once the connection is open
  • Server can push instantly to interested clients
Cons
  • Holding millions of connections strains memory and load balancers
  • Requires reconnection, heartbeat, and backpressure handling
  • Stateful connections complicate horizontal scaling and deploys

Decision Guide

Decision Guide

Choose polling (long polling if latency matters) when updates are infrequent, clients are numerous but idle, or you want to stay purely on stateless HTTP infrastructure. Choose WebSockets for chat, live collaboration, trading tickers, or games where sub-second, bidirectional updates justify the connection-management cost. Consider Server-Sent Events for one-way push.

Real-World Examples

Slack / WhatsApp Web
Use WebSockets for real-time messaging
Trading platforms
Push live price ticks over WebSockets
GitHub Actions logs
Historically used long polling for status
Figma
WebSockets for multiplayer document editing

Interview Questions

How does long polling differ from short polling?

Short polling requests on a fixed interval and often gets empty responses; long polling holds the request open until data is ready or it times out, cutting wasted requests and latency while still using standard HTTP.

Why are WebSockets harder to scale than stateless HTTP?

Each client keeps an open, stateful connection pinned to a specific server, so load balancers need connection awareness, memory grows with connection count, and deploys must drain sockets gracefully — unlike stateless requests any node can serve.

60-Second Revision
  • →Polling = repeated HTTP requests; short (timer) or long (held open).
  • →WebSockets = one persistent, full-duplex, low-latency connection.
  • →Polling is simple and stateless but wastes requests / adds latency.
  • →WebSockets give instant push but hold stateful connections.
  • →Polling for infrequent updates; WebSockets for true real-time.

Related

Everything on Archprimer is connected — follow the graph.