Polling and Long Polling: when WebSocket is overkill
Understand Short Polling and Long Polling, how to implement each from backend to frontend, and when they're the best choice over WebSocket.
Thiago Saraiva

Overview
Polling and Long Polling are techniques for the client to get updated data from the server when the server cannot initiate communication (as WebSocket does). This guide covers complete implementations from database to frontend, including comparison with SSE and WebSocket.
1. Fundamentals
Short Polling
Client makes periodic requests at a fixed interval.
- Client sends request
- Server responds immediately (with or without new data)
- Client waits N seconds
- Repeats
Simple, but wastes bandwidth with empty responses.
Long Polling
Client makes a request and the server holds the connection until it has data.
- Client sends request
- Server holds the connection until it has data or timeout
- Server responds when there's new data
- Client immediately makes a new request
Efficient, near real-time without WebSocket.
| Characteristic | Short Polling | Long Polling | SSE | WebSocket |
|---|---|---|---|---|
| Direction | Client → Server | Client → Server | Server → Client | Bidirectional |
| Protocol | Standard HTTP | Standard HTTP | HTTP (stream) | WS (upgrade) |
| Latency | Interval/2 (average) | ~instant | ~instant | ~instant |
| Requests per minute | ~12-60 (wasteful) | Only when there's data | 1 continuous connection | 1 continuous connection |
| Complexity | Trivial | Medium | Low | High |
| Proxy/LB compat | Perfect | Timeout configs needed | Good | Requires WS support |
| Firewall compat | Perfect | Standard HTTP | Standard HTTP | Some block it |
| Scale (10K clients) | ~600K req/min | ~10K hold connections | ~10K hold connections | ~10K hold connections |
Why is Long Polling still relevant? WebSocket and SSE are superior, but Long Polling works on any HTTP infrastructure without special configuration. It's the universal fallback — used by Firebase Realtime Database, Slack (as fallback), and CometD.
2. Database Layer
PostgreSQL LISTEN/NOTIFY — Trigger for Long Polling
Database Polling — "updated_at" Pattern
Redis Pub/Sub as Long Polling Backbone
3. Backend Layer
Short Polling — Express
Long Polling — Complete Express
Long Polling — Python FastAPI
Nginx — Long Polling Configuration
Scaling — Multiple Instances with Redis
4. Frontend Layer
Short Polling — React with React Query
Short Polling — Vanilla JavaScript
Long Polling — Complete React Hook
Long Polling — Vanilla JavaScript
5. Real-World Use Cases
Chat with Long Polling (Firebase-style)
Deployment Status Polling
Typing Indicator with Short Polling
Mobile — Polling with Battery/Network Awareness
6. Pitfalls and Optimizations
Common pitfalls:
- Thundering herd: 10K clients reconnect at the same time after timeout. Solution: add random jitter to reconnect delay
- Proxy timeout: Nginx/ALB close idle connections before long poll responds.
proxy_read_timeoutmust be greater than the long poll timeout - Memory leak: Waiters not removed when client disconnects. Always clean up on the
req.on('close')event - Stale connections: Client believes it's connected but the connection died. Use periodic heartbeat
- Clock skew:
sincetimestamp can diverge between client and server. Always useserverTimefrom the response, neverDate.now()from the client
7. Performance
| Metric (10K users) | Short Polling (5s) | Long Polling (30s timeout) | WebSocket |
|---|---|---|---|
| Requests per minute | 120,000 | ~20,000 (reconnections only) | 0 (persistent connection) |
| Bandwidth (no data) | ~48 MB/min (headers) | ~8 MB/min | ~0 (idle pings) |
| Delivery latency | 0-5000ms (avg 2.5s) | ~50ms | ~10ms |
| Simultaneous connections | ~0 (instant) | ~10,000 (hold) | ~10,000 (persistent) |
| DB load (empty polls) | 120K queries/min | ~20K queries/min | 0 (event-driven) |
8. Decision Framework
Use Short Polling when:
- Update interval of 5-60s is acceptable
- Implementation needs to be trivial
- Few simultaneous users (< 1K)
- Endpoint already exists (just add refetchInterval on frontend)
- Metrics dashboards, deploy status, notification badges
Use Long Polling when:
- You need near-realtime without WebSocket
- Infrastructure doesn't support WS (firewalls, legacy proxies)
- Fallback for when WebSocket fails
- Simple chat, notifications, basic collaborative editing
Prefer SSE/WebSocket when:
- High volume of events (> 1 event/second)
- Many simultaneous users (> 10K)
- Intensive bidirectional communication (gaming, trading)
- Bandwidth is critical (mobile, low-bandwidth)