Request-response, streaming and the options between
Long polling, SSE, WebSocket, gRPC, WebTransport and job handles each fit a different shape of conversation. Learn to pick by direction, reconnection and what sits in the path.
Plain HTTP is request-response: the client asks, the server answers once, done. Many things do not fit that shape. A model produces tokens over 20 seconds. A collaborative editor needs both sides to send at any time. A video call needs low latency more than reliability. A five-minute agent task outlives any sensible connection.
Who talks when
| Option | Direction | Reconnect | Best fit | Main trap |
|---|---|---|---|---|
| Server-Sent Events | Server to client | Built in with Last-Event-ID | Token streams, progress | Proxy buffering; six-connection limit on HTTP/1.1 |
| WebSocket | Both ways | Build it yourself | Voice, collaboration, realtime control | Stateful load balancing; no backpressure in the basic browser API |
| gRPC | Unary plus three streaming modes | Build it yourself | Service to service | Needs a proxy or Connect in browsers; L4 balancers pin connections |
| WebTransport | Both ways, plus datagrams | Build it yourself | Low-latency media and games | Needs an HTTP/3 path and a fallback |
| Job handle and polling | Client pulls | Built in: each poll is new | Long-running work | Polling cost and delay |
A decision in three questions
- 01Does the client need to send during the stream?
If not, use SSE: it is plain HTTP, works through proxies and CDNs, and the browser reconnects for you. LLM token streaming is in this group.
- 02Is the work longer than a connection should live?
Minutes or more: return a job or task handle immediately and let the client poll or subscribe. Connections break; handles do not.
- 03Do you need two-way, low-latency messages?
WebSocket for browsers today; WebTransport where HTTP/3 is available and you want datagrams or many independent streams.
Go deeperLong polling, the ancestor of everything here
Before SSE and WebSocket, browsers had only request-response. Long polling faked push: the client sends a request, the server holds it open until there is news or a timeout, responds, and the client immediately sends another. It works through every proxy, which is why it survived as a fallback.
Its costs are a request per message and a gap between responses where events must be queued on the server. SSE removed both by keeping one response open and writing many events into it.
Where you will meet it
Model chat UIs stream responses with SSE, and send the next user message as a separate POST.
Realtime voice APIs use WebSocket or WebRTC, because audio flows both ways continuously.
Long agent runs are exposed as tasks with IDs. The UI subscribes to a run's event log and can reattach after a refresh.
Words to know
- Long polling
- Holding a request open until there is data, then immediately re-requesting.
- Full duplex
- Both sides can send at the same time.
- Job handle
- An ID returned for long work, used to check status or fetch results later.
Check yourself
Answer out loud before you open each one.
SSE or WebSocket for a chat UI?
SSE, unless the client must send on the same channel during generation.
When do you prefer a job handle over a stream?
When the work can outlive a connection, from minutes to hours, or when the client may disconnect and return.
Why does SSE work better through corporate proxies than WebSocket?
It is an ordinary HTTP response. WebSocket needs an upgrade that some proxies mishandle or block.
Try it
List three features you use daily (a chat app, a stock ticker, a CI job page) and pick a protocol for each with one sentence of justification.