LearnThatStack Ace your next interview
AI System Design · question
Question 4 of 54

Why is streaming important for LLM UX, and what does it change about your architecture?

beginner
← All AI System Design questions
Re-explain

Streaming sends tokens as the model writes them, so the user reads the first words in under a second, not a spinner. Total time barely changes. The wait just feels shorter.

It changes the architecture because the reply stops being one JSON object. You hold a connection open, usually with Server-Sent Events (SSE), a one-way stream over HTTP. Every hop must forward chunks without buffering, and proxies, gzip and gateways buffer by default.

The HTTP status goes out before the answer exists. So a mid-stream failure needs an in-band error event, not a 500. Token counts also arrive last, so keep a copy of the stream on the server for logging, caching and output checks.

let full = '';
for await (const chunk of stream) {
  full += chunk.delta;                       // server-side copy
  res.write(`data: ${JSON.stringify(chunk)}\n\n`);
}
res.write(`event: done\ndata: ${JSON.stringify(usage)}\n\n`);
await logAndCache(full);                     // only possible after the last chunk

If the user stops a bad answer, abort the upstream call. Otherwise you pay for tokens nobody ever sees.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
Guided practice for AI System Design One question at a time. Answer out loud, get graded, see what you missed.
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens How interviewers actually use this question

Likely follow-ups

  • How do you run output checks like moderation when users see tokens before the full answer exists? Check the text in windows as it arrives, hold back a small buffer, and send an in-band event to stop or retract the answer if a check fails.
  • How do you stream a tool call or JSON output when the JSON only parses once it is complete? Buffer tool-call arguments until they are complete and validate them before running anything. Stream only the text the user reads.
  • How does streaming hold up at scale, with thousands of open connections and clients that drop mid-answer? Name idle timeouts and buffering at load balancers, connection limits per server, and resuming a stream from the last event ID.
  • Which latency numbers would you track to show that streaming actually helped? Time-to-first-token for perceived speed and total latency for the full reply, as percentiles. Streaming mostly moves the first one.

What you can say

  1. Streaming sends tokens as the model writes them, so the user reads the first words in under a second. Total time barely changes, but the wait feels shorter.
  2. It changes the architecture because the reply stops being one JSON object. I hold a connection open, usually with Server-Sent Events, a one-way stream over HTTP.
  3. Every hop has to forward chunks as they arrive, and proxies, gzip and gateways buffer by default, so I check each one.
  4. The status code goes out before the answer exists, so a failure halfway through has to be an error event in the stream, not a 500.
  5. Token counts come last, so the server keeps its own copy of the text for logging, caching and output checks after the final chunk.
  6. The catch is cost when users stop early. If someone cancels a bad answer, I abort the upstream call, or we keep paying for tokens nobody sees.

Weak answers to avoid

  • Says streaming makes the model faster Total time barely changes. Say it cuts the time to the first words and makes the wait feel shorter, then move on to what it changes in the system.
  • Says 'use SSE' and ignores buffering along the path Proxies, gzip and gateways buffer by default, so the chunks arrive in one lump. Say every hop must forward chunks as they come.
  • Relies on HTTP status codes for errors The 200 is already sent when the model fails halfway. Describe an in-band error event that the client handles, and what the UI shows.
  • Forgets logging, usage and cancellation Token counts arrive last, and a closed tab does not stop the model call. Keep a server-side copy, log after the done event, abort upstream on stop.
Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the AI System Design cheatsheet.

← Back to all AI System Design questions
Pro · $10/mo

47 of 54 AI System Design answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime