LLM System Design: Designing a ChatGPT-Style Chat Assistant
Walk the classic 'design ChatGPT' interview case step by step: TTFT, KV cache sizing, SSE streaming, continuous batching and conversation memory.
New12 min read

LLM system design questions such as "design ChatGPT" or "design a chat assistant that streams answers to millions of users" come up often in senior rounds. It looks like a normal chat app with one extra API call, and that is the trap. A language model call is slow, it streams, it eats GPU memory, and GPUs are most of the bill. The candidates who do well size the system in tokens and memory, not in requests.
This guide is for backend developers who know REST, queues and databases. You will walk one full case: the requirements that matter (time to first token and inter-token latency), the rough estimates, the streaming API, the blueprint, and the deep dives an interviewer usually picks: GPU batching, admission control and conversation memory.
We follow the five TRIBE steps from the TechTribers System Design book: Think requirements, Rough estimates, Interfaces, Blueprint, Evolve.
In this guide
- How one LLM request behaves: prefill, decode and the KV cache
- T: Think requirements
- R: Rough estimates in tokens and memory
- I: Interfaces and streaming over SSE
- B: Blueprint
- E: Evolve, the deep dives
- What to say in the interview
From the book: this guide is based on Case 13 of System Design 2026: Classic + AI Era, where 18 case studies are worked step by step, with runnable Java labs. Read the free 5-page sample on the book page.
How one LLM request behaves: prefill, decode and the KV cache
A model reads and writes tokens. A token is a piece of text, about four English characters on average. Serving one request happens in two phases:
- Prefill: the model reads the whole prompt in one parallel pass. This phase is compute-heavy.
- Decode: the model writes the answer one token at a time, and each new token depends on all the tokens before it. This phase is memory-bound.
So an LLM call has two latency numbers, not one. Time to first token (TTFT) covers the wait in the queue, the prefill and the network. Inter-token latency is the gap between one streamed token and the next.
The third idea is the KV cache. Decode needs the attention keys and values of every earlier token, so the server keeps them in GPU memory instead of recomputing them. The cache grows linearly with sequence length and with the number of requests in the batch.
You can call a hosted model API or run open models yourself with a server such as vLLM (or Ollama on a laptop). This case runs its own replicas, so batching and GPU memory are your problem.
T: Think requirements
Spend about five minutes here, in two columns.
Functional
- Send a message; the answer streams in; the user can stop it.
- Keep chat history so users can reopen old conversations.
- Free and paid plans, each with its own limits.
Non-functional
- The first words arrive fast.
- Under overload, the system says "busy" quickly instead of hanging.
- Paid users never starve behind free traffic.
- The cost of each turn stays bounded.
Say what is out of scope: training, document search, agents and guardrails.
Three questions to ask first
- How long do chats get? This decides KV memory and the cost of each turn.
- Hosted model API or our own GPUs? This decides who owns batching.
- What first-token target does each plan get? This decides admission control.
R: Rough estimates in tokens and memory
The numbers below are the book's estimates, computed by its script estimates/cs13_chat_llm.py from stated assumptions. They are not measurements. Say the assumptions out loud:
- 200 million chat turns per day, peak factor 3.
- 2,000 input tokens per turn (system prompt, resent history and the new message) and 400 output tokens.
- Each reply streams at 40 tokens per second, faster than people read.
- One model replica sustains 3,000 output tokens per second with continuous batching. The script marks this as an assumption: measure your own.
- Model shape: 32 layers, 8 KV heads, 128 head dimensions (an assumed 8B-class model with grouped-query attention).
- 3,000 bytes stored per turn, history kept for 365 days.
What the script gets
- Turns per second: about 2.3k on average, about 6.9k at peak.
- Prefill tokens per second at peak: about 14 million.
- Output tokens per second at peak: about 2.8 million.
- Concurrent streams at peak: about 69k (peak turns times 400 tokens, divided by 40 tokens per second).
- Model replicas for peak output: 926, so about 930 plus headroom for prefill.
- KV cache per token: 131,072 bytes, about 130 KB.
- KV cache per sequence of 2,400 tokens: about 310 MB.
- KV cache for all live streams at peak: about 22 TB, which is about 24 GB per replica.
- Chat history for one year: about 220 TB.
Here is the KV arithmetic, shortened from the book's script:
shape = 32 * 8 * 128 # layers x KV heads x head dim
KV = 2 # one K and one V vector per layer per KV head
FP16 = 2 # bytes per value in fp16/bf16
kv_tok = shape * KV * FP16 # 131,072 B per token
kv_seq = (tok_in + tok_out) * kv_tok # ~310 MB per sequence
kv_all = streams * kv_seq # ~22 TB for ~69k live streams
kv_per_replica = kv_all / reps # ~24 GB on each of 926 replicasThe sentence to say: about 69k streams times about 310 MB of KV cache each means memory, not compute, caps concurrency. Trimming history, prefix caching and admission control follow from that.
I: Interfaces and streaming over SSE
Three endpoints are enough:
POST /chats/{id}/msgs: send a message. The response is a stream of delta events, then a done event that reports the token count. Answers: 200 (SSE), 429 (over the plan's limit), 503 (busy).GET /chats/{id}/msgs: history, newest first. Answers: 200.POST /chats/{id}/stop: stop the answer and free its GPU slot. Answers: 202.
Server-sent events (SSE) fit because the traffic is one-way: the client sends one message, the server pushes many small pieces back. The server answers with the MIME type text/event-stream; each message is one or more field: value lines (event, data, id or retry), and a blank line ends the message. Here is a sketch of one answer's stream. The event names follow the book's "delta, then done" contract; the JSON payloads and the token count are placeholders, not real output:
event: delta
data: {"text": "First words"}
event: delta
data: {"text": " of the answer"}
event: done
data: {"outputTokens": 400}Two points to say out loud. First, streaming cuts the time to the first token, not the time to the last one. Second, the stop endpoint matters: an abandoned answer holds its KV cache until the server cancels it, so stop must reach the replica. And per MDN, without HTTP/2 a browser allows only six SSE connections per domain across all tabs, so serve the stream over HTTP/2.
B: Blueprint
Draw the boxes and number one message's path:
- The chat app sends the message and keeps an SSE stream open.
- The API gateway checks the key and the plan's request and token limits, using counters in Redis.
- The chat service builds the prompt from a summary of old turns plus the recent turns, read from the conversation store.
- It puts the request on a queue for its plan. A full free queue answers 503 busy at once.
- A model replica admits the request into its running batch. Tokens stream back the way the message came, and the reply is saved at the end.
Off the hot path, a summariser running a small model compresses old turns. A metrics box watches TTFT and KV cache use.
Why a wide-column store such as Cassandra? Keyed by chat id plus a sequence number, "the recent turns of this chat" is one read, and about 220 TB a year spreads across nodes by that key.
E: Evolve, the deep dives
This is the longest part of the round: 15 to 20 minutes on the two or three deep dives the interviewer picks.
Deep dive 1: TTFT, queues and GPU batching
Two forces meet here. People decide whether the assistant feels fast from how soon text appears, and GPU time is the largest cost. The estimate already said roughly 930 replicas, plus room for prefill. Each replica's batch is limited by its share of KV memory, about 24 GB; once that is used up, the engine has to preempt a running request.
The key serving technique is continuous batching, which the Orca paper called iteration-level scheduling: the server schedules one model step at a time, and each step adds one token to every running request. When a request finishes, its KV memory is freed at once, and a queued request joins on the next step.
Serving engines also manage the KV cache carefully. vLLM stores it in fixed-size pages (PagedAttention) and shares blocks between prompts that start with the same prefix; its paper reported 2 to 4 times the throughput of FasterTransformer and Orca at the same latency. The book flags this as fast-moving: re-check engine details before you quote them.
The second half is admission control. Keep one queue per plan. At peak, free work gets a fast 503 instead of a long wait, so paid TTFT holds. Limits count tokens per minute (TPM), not requests, because GPU load follows tokens. The book's lab-llm-gateway has a token bucket that reserves the prompt estimate plus max_tokens before the call and refunds the unused part after it:
/** Takes n tokens before the call, or nothing if there are too few. */
public synchronized boolean tryReserve(long n) {
refill();
if (tokens < n) {
return false;
}
tokens -= n;
return true;
}
/** After the call: give back what was reserved but not used. */
public synchronized void settle(long reserved, long used) {
refill();
tokens = Math.min(capacity, tokens + reserved - used);
}The refund matters. In the book's recorded lab run (on a 4 vCPU Intel Xeon build machine), a tenant with a 6,000 tokens-per-minute limit sent 200 requests at once: 166 got through with the refund, only 28 without it, roughly six times more.
Deep dive 2: conversation memory
A model remembers nothing between calls, so each turn sends the history again. A long chat therefore gets slower, dearer and closer to the context-window limit with every turn. The fix is a fixed prompt budget, stable parts first:
- The system prompt, which never changes.
- A rolling summary of old turns, written by the async summariser.
- The last few turns, verbatim.
- The new message.
The order is deliberate. Per the vLLM docs, prefix caching keeps the KV blocks of processed requests, and a new request that starts with the same tokens reuses them instead of recomputing; it does not change the model's output. Only a shared start counts, so stable parts go first.
- Resend full history: the prompt, cost and TTFT grow every turn; old detail is kept word for word.
- Summary plus recent turns: each turn stays near the 2,000 input tokens the estimate assumed; old detail gets blurred.
Deep dive 3: what breaks at 10x
- You cannot buy ten times the GPUs. Route easy turns to a smaller model and tighten free-plan admission.
- KV memory fills on long chats. Lower the history budget, share prefixes, and split prefill and decode.
- Conversation store writes grow. Partition by chat id and move old chats to object storage.
Follow-ups to practise
- A user's tab closes mid-answer. Detect the dropped stream, cancel the request and free its KV cache.
- Exam-results night triples free traffic. Cap the free queue's wait and answer 503 with
Retry-After. - "Remember facts from last month's chats." Store facts per user and retrieve a few for each turn.
What to say in the interview
One line worth saying in your own words: stream answers over SSE and watch TTFT and inter-token latency, not only total time. Interviewers listen for this:
- You size GPUs from tokens and KV memory, not from requests per second.
- You separate TTFT from inter-token latency.
- Overload is a fast "busy", not a long wait for everyone.
- You budget the prompt, stable prefix first.
And the red flags: treating an LLM call like a quick REST call, resending the whole history on every turn, and generating tokens after the user has left. Close with the three trade-offs: bigger batches cut cost per token but slow each stream; a summary bounds the prompt but blurs detail; refusing free users at peak beats making everyone wait.
Go deeper
This article follows Case 13, "Chat assistant with LLM serving", and building block 16, "AI building blocks", in System Design, 2026 Edition: Classic + AI Era (TechTribers Guide Series, Book 2). There you get the whole case on one redrawable page, the full estimate table with the reason for each assumption, and practice follow-ups. The companion labs add the estimate scripts and the LLM gateway lab (token buckets, model routing with fallback, a semantic cache), with tests that run on JDK 25.
See it at System Design: Classic + AI Era. The product page has a free 5-page sample.
Related reading
- A step-by-step system design interview framework
- Back-of-the-envelope estimation for system design
- LLM token optimization guide
Official references used here: MDN: Using server-sent events and vLLM: automatic prefix caching.
FAQ
How do you design ChatGPT in a system design interview?
Walk five steps: requirements (streaming, stop, history, plans, fast first token), estimates in tokens and KV memory, three endpoints with SSE, a blueprint of gateway, chat service, conversation store, per-plan queues and model replicas, then deep dives on batching, admission control and conversation memory.
What is the difference between TTFT and inter-token latency?
Time to first token is the wait before the first word appears: queueing, prefill and the network. Inter-token latency is the gap between streamed tokens after that. A design can be good at one and bad at the other, so measure both.
Why is the KV cache the bottleneck in LLM serving?
The KV cache stores attention keys and values for every token of every live request, and it grows with sequence length and batch size. In the book's estimate one 2,400-token sequence needs about 310 MB, so memory, not compute, caps how many answers can stream at once.
Why use SSE instead of WebSockets for streaming LLM answers?
The traffic is one request in and many small pieces out, which is what server-sent events do over plain HTTP. A separate stop endpoint covers the one thing the client sends mid-stream. Serve it over HTTP/2 to avoid the browser's six-connection limit.
What is continuous batching?
It is scheduling one model step at a time instead of one whole request at a time. Finished requests leave the batch at once and free their memory, and queued requests join on the next step.





