Workspace

Request-response, streaming and the options between

3 day streakD

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.

BasicsLesson 1 of 616 min

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.

Figure 1.1

Who talks when

Request–responseOne question, one answer
Server-Sent EventsOne request, a stream of events back
WebSocketEither side, any time
gRPC bidirectionalTwo typed streams on one HTTP/2 stream
Job handleStart, then short polls with the ID
Client to serverServer to client
Five patterns side by side. Arrows show which side sends and when. SSE streams one way over an ordinary response. WebSocket and WebTransport are two-way. gRPC supports four call shapes. A job handle turns long work into short polls.
OptionDirectionReconnectBest fitMain trap
Server-Sent EventsServer to clientBuilt in with Last-Event-IDToken streams, progressProxy buffering; six-connection limit on HTTP/1.1
WebSocketBoth waysBuild it yourselfVoice, collaboration, realtime controlStateful load balancing; no backpressure in the basic browser API
gRPCUnary plus three streaming modesBuild it yourselfService to serviceNeeds a proxy or Connect in browsers; L4 balancers pin connections
WebTransportBoth ways, plus datagramsBuild it yourselfLow-latency media and gamesNeeds an HTTP/3 path and a fallback
Job handle and pollingClient pullsBuilt in: each poll is newLong-running workPolling cost and delay

A decision in three questions

  1. 01
    Does 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.

  2. 02
    Is 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.

  3. 03
    Do 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

Chat interfaces

Model chat UIs stream responses with SSE, and send the next user message as a separate POST.

Voice agents

Realtime voice APIs use WebSocket or WebRTC, because audio flows both ways continuously.

Agent tasks

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.

A good place to start

Explore a pattern

A little guidance

Start with a pattern, read through a problem, and mark it solved when the idea clicks. Save anything you want to revisit.

New tutorials are added one at a time. Your bookmarks and solved checkmarks stay in this browser.

Explore the roadmap