These are the four common ways for a server to get fresh data to a client. Polling asks repeatedly. Long polling asks and waits until there's something to say. Server-Sent Events (SSE) keep one HTTP response open and stream events down it. WebSockets upgrade a connection into a full two-way channel. The choice decides latency, server cost and complexity for anything "live": chat, notifications, dashboards, streaming AI responses.
Polling is a child asking "are we there yet?" every minute. Long polling is asking once and the driver answering only when you've arrived. SSE is the driver announcing each town as you pass it. A WebSocket is an open phone call where both sides can talk anytime.
Short polling client: GET /updates (every 5 s) -> usually "nothing new"
simple; wasteful; latency up to the interval
Long polling client: GET /updates -> server holds it open until data or
timeout (~30 s) -> responds -> client immediately asks again
near-real-time over plain HTTP; one request per message
SSE client: GET /stream (Accept: text/event-stream)
server keeps writing "data: ...\n\n" events on the response
one-way (server -> client), auto-reconnect, text only
WebSocket HTTP request with "Upgrade: websocket" -> 101 Switching Protocols
then a persistent full-duplex TCP channel, frames both ways
| Direction | Latency | Server cost | Good for | |
|---|---|---|---|---|
| Short polling | client asks | up to interval | many empty requests | rare updates, simplest setups |
| Long polling | client asks, server waits | low | held requests + re-requests | fallback when others are blocked |
| SSE | server → client | low | one open connection | notifications, feeds, LLM token streaming |
| WebSocket | both ways | lowest | one open connection, stateful | chat, multiplayer, collaborative editing |