The push problem
Plain request response cannot let a server deliver data the moment it appears. Three techniques close that gap, each with different cost and direction.
The three options
- Long polling: the client makes a request that the server holds open until data arrives or it times out, then the client immediately asks again. Simple and works everywhere, but each message restarts a request.
- Server sent events: the server keeps one connection open and streams a one way feed of events to the client over plain HTTP. It auto reconnects but flows server to client only.
- WebSocket: a full duplex persistent connection where both sides send freely after an upgrade handshake. Best for true two way, low latency traffic like chat.
Choosing
- One way updates like a live feed favor SSE for its simplicity.
- Interactive two way traffic favors WebSocket.
- Long polling is the fallback where the others are unavailable.
Key idea
Long polling is the universal fallback, SSE streams one way cheaply, and WebSocket gives full duplex for interactive apps.