Video in progress
How do you tell short polling, long polling and WebSocket apart?
Short polling: the client asks every N seconds and often gets an empty answer. Long polling: the server holds the response until new data appears. WebSocket: one persistent connection, and either side can write at any time.
📖 Answer
Take one example: you need to show an order status in real time.
| Approach | How it works | Downside |
|---|---|---|
| Short polling | GET /orders/42 every 3 seconds with setInterval |
many empty requests, latency equals the interval |
| Long polling | GET /orders/42/wait: the server waits up to 30 seconds and answers immediately if something changes |
the client must reconnect after every response, and waiting requests pile up on the server |
| WebSocket | connects once, the server sends a message when the status changes | stateful, proxies and scaling are harder |
Short polling is the simplest and works everywhere. With 1000 users and a 10-second delay being acceptable, it's enough.
Long polling used to be a good fallback for environments where WebSocket doesn't work; SockJS uses it internally too.
WebSocket pays off when messages are frequent and flow in both directions: chat, games, live dashboards.
Sign up to mark studied questions and save your progress.