KatInterview

Architecting a Streaming LLM Chat Front End

System DesignModel answer
HardModel answerSystem Designfrontendstreamingvirtualization

Last updated

Design a browser client that streams model output into a virtualized, richly formatted chat log while surviving dropped connections and branching edits.

Context

You are asked to architect the browser-side of a conversational AI product: a single-page app where users hold long back-and-forth conversations with a language model. The model's output arrives incrementally, one fragment at a time, and the transcript must feel instant even when it grows to hundreds of messages with code blocks, images, and math.

Treat this as a front-end system design interview. The server and model are given; your job is the client architecture.

What the client must do

  1. Incremental output. Tokens arrive continuously while the model is generating. The UI must show them as they land without stuttering scroll or blocking typing in the composer.
  2. Long transcripts. A conversation can hold roughly a thousand messages, some of them tens of thousands of tokens long. Scrolling must stay smooth and initial load must not require fetching everything.
  3. Rich content. Render Markdown (paragraphs, lists, tables), highlight fenced code, and typeset math delimited with $...$ / $$...$$. Messages may also carry images.
  4. Message actions. The user can edit an earlier prompt, ask for a fresh response to the same prompt (a variant), stop generation mid-stream, copy content, and retry a failed response.

Non-functional targets

  • The first arriving fragment should be visible within about one frame of reaching the client.
  • Steady-state updates should never push the main thread past a frame budget on a mid-range phone.
  • The visible thread must stay consistent across the local cache, the server record, and other open tabs.
  • A dropped connection mid-generation must not lose output that the server already produced.

Deliverables

  • A component/data-flow overview of the client.
  • How fragments move from the network into rendered state.
  • Schemas for a conversation and a message.
  • Your rendering strategy for very long logs, and how you handle network failure. Mention the trade-offs you weighed.

Hints

Hint 1

Model the transcript as a tree rather than an array — edits and regenerations create siblings, and rendering is just a walk from the current leaf up to the root.

Hint 2

Decouple the arrival rate of fragments from the render rate: accumulate deltas in a buffer and publish to the store at most once per animation frame.

Hint 3

Only the tail block of a streaming message is unstable; memoize every closed Markdown block by content hash so per-frame parse cost stays constant as the message grows.

Hint 4

Give the server a durable per-message stream with sequence numbers so a reconnect can resume from the last seen index, and treat the client cache as a derive-only replica.