Book Deep Read · Generative AI System Design Interview · Ch 1
Generative AI System Design Interview · Ch 1 · Ali Aminian, Hao Sheng & Alex Xu · 2024
You let an AI finish your sentence in an email, draft a weekly report, or paint a picture from one line of text. Behind each of those products is not just "a clever model" but a whole system. This book is about designing such systems, and Chapter 1 hands you the blueprint: when someone asks you to build a product that generates things, in what order should you think, and where do people fall over?
Older AI was more like a sorter: show it a photo, it says "cat" or "dog" — one answer, obviously right or wrong. Today's AI is more like a cook: ask for scrambled eggs and tomato and you get a hundred defensible versions, none of them "the" answer. It sounds like a small change of job. For the people building the system, it overturns three basic rules at once.
One: you can no longer mark the exam. A sorter is checked against the answer key. A cook has to be tasted, and "tasty" was never the same for two people.
Two: you are now billed by the word. A single old-style judgement cost almost nothing. This thing burns compute for every word it emits, and a chattier version can multiply the bill.
Three: when it is wrong, it does not cry out. Old systems crash, time out, throw errors. This one says the wrong thing beautifully — unless you go and check, you cannot tell.
The heart of the chapter is breaking the build into seven steps, each answering one concrete question. ① Pin down what you actually want — how fast, how much per request, and what must never be said. ② Decide what the job really is — writing, drawing, speaking — and fix exactly what goes in and what comes out. ③ Gather the ingredients: where the data comes from and how the dirty parts get washed. ④ Pick the method (more on that below). ⑤ Taste it — on what grounds do you claim this version beats the last? ⑥ Serve it: put it in front of real users, fast and cheap. ⑦ Keep watching, because the world shifts and it quietly gets worse.
The most valuable thing in step four is a money-saving rule: capability comes on four steps of a ladder, and you start on the cheapest one and only climb when it isn't enough.
Step one: just talk to it properly — spell out what you want; you can try this in an afternoon. Step two: hand it a stack of documents to look things up in — have it read your own files before answering, which cures "it doesn't know anything about our company". Step three: train it specially — put a few hundred to a few thousand of your own examples through it, which cures "it knows, but the tone and the format are wrong". Step four: raise one from scratch — months of work and thousands of GPUs, which most teams will never need. Each step up buys control, and can cost a thousand times more in money and time.
Building a generative product is not about finding a cleverer model. It is that three old rules changed: there is no answer key, so you have to define what "good" means yourself; every word costs money, so thrift is a design problem and not a finance problem; and it lies fluently, so somebody — a person or another model — has to be assigned to check. The rest is following those seven steps.
Want the mechanisms, the notation and the diagrams? → Switch to the deep read
You think a generative system design question is about picking a model. It is about everything around the model. This chapter is the book's spine: it breaks "design a system that generates content" into seven steps — clarify requirements, frame it as a generative task, prepare data, develop the model, evaluate, deploy and serve, monitor and iterate — and names the three root differences from its sibling volume on discriminative ML systems: evaluation has no answer key, cost is billed per token, and failure sounds fluent. Those three decide nearly every trade-off in the ten case studies that follow.
This is the only chapter in Part I of Aminian, Sheng and Xu's Generative AI System Design Interview (2024), and the template the ten case studies in Ch2–11 all follow. It inherits the seven-step framework of the sibling Machine Learning System Design Interview, but changes the subject: that volume designs discriminative systems whose output is a label or a score, this one designs generative systems whose output is a sequence, an image or a video. In the real world that maps onto smart compose, machine translation, assistants, RAG question answering, text-to-image and text-to-video.
Handed "design ChatGPT" or "design a text-to-image product", the usual failure is to dive straight into architecture — how many Transformer layers, how many diffusion steps. Not wrong, but it skips what actually decides the outcome: what is the latency budget (a completion product must land before the user's next keystroke, commonly tens of milliseconds to about a hundred; a chat product can spend a few hundred milliseconds on the first token as long as words keep flowing), how much may one request cost, on what grounds is this version better than the last, and how will you notice it quietly getting worse.
The deeper pain is that the failure mode changed. When a discriminative system is wrong, it is wrong visibly: probabilities skew, metrics drop, alerts fire. When a generative system is wrong, it is wrong fluently: HTTP 200, normal latency, zero error rate — the content is simply invented. No infrastructure metric will ever tell you. Ignore that and you ship a system that demos beautifully and gets screenshotted onto social media three months later.
A discriminative model maps an input into a finite output space. A generative model's output space explodes combinatorially: a 500-token answer has on the order of vocabulary-size-to-the-500th possibilities (|V|^500 — all you need from the notation is "too many to enumerate"). Three consequences run through the whole book.
(1) There is no single correct answer, so there is no accuracy to compute. Two answers can both be right and both be good, differing only in style — evaluation has to be designed, not selected off a shelf.
(2) Cost moves from "one inference" to "per token". A discriminative model produces its answer in one forward pass, at roughly constant cost. A generative model emits N tokens autoregressively, which is N forward passes — output length is cost, and output length is latency. This constraint comes back to bite in every later chapter.
(3) Failure is fluent. An uncertain discriminative model returns a probability near 0.5, and that signal can drive a threshold or a handoff to a human. An uncertain generative model keeps writing smoothly; its confidence is not externalized. So a generative system must build a layer of visibility that does not come for free — citations, groundedness checks, guardrails, sampled review — before you can know when it was wrong.
Against the sibling framework, two changes stand out.
Feature engineering largely leaves the stage. The most labour-intensive step in a discriminative system — turning raw data into columns of features — is replaced by two things: data curation on the training side (dedupe, filter, mix) and context construction on the inference side (what to retrieve, where in the prompt to put it, how to fit it in the window). The context window is the new feature budget: it has a hard ceiling, and what goes in is a design decision.
Evaluation goes from one step to a through-line. In the sibling volume evaluation is "offline metrics → online A/B", two steps and done. Here, because there is no answer key, the evaluation itself must first be designed: define what good means, then decide who judges, how many cases, and how to keep the cost down. Nearly every one of the ten case studies needs its own.
Clarifying requirements matters more here than in a discriminative question, because what you are nailing down is four budgets that fight each other:
The test is blunt: until those four are nailed down, talking about model selection is empty.
Step four, "model development", rarely means training one from scratch. It means choosing a rung on a capability ladder: prompt engineering → RAG → fine-tuning → continued pretraining or training from scratch. Each rung up buys control and costs an order of magnitude more in both time and unit price.
The test for picking a rung is startlingly plain: ask whether that rung treats your actual disease. "It doesn't know anything about our company" is a knowledge gap and calls for RAG. "It knows, but the tone is wrong, the format is wrong, it won't follow our procedure" is a behaviour gap and calls for fine-tuning. Getting these backwards — fine-tuning to inject facts, prompting to fix behaviour — is the most common and most expensive mistake in the field.
Three routes, used together. Automatic metrics (BLEU / ROUGE against a reference, perplexity, FID for images) are cheap enough to run on every commit, but they only measure surface overlap and nearly break down on open-ended answers — say the same thing differently and the score drops. LLM-as-judge scores against a rubric with a strong model, scaling to tens of thousands of cases in minutes, at the price of its own biases: it prefers long answers, is swayed by option order, and favours outputs from its own family. Human review is the most trustworthy and costs tens of seconds to minutes per case, which means it can only ever sample.
The working answer is to layer them: the model judge runs the full set as the daily regression, humans sample to calibrate the judge itself, and online A/B or side-by-side battles (Elo) show what real people prefer. One trick you can copy directly comes from KDDI's RAG application: turn the judge's 1–5 rating into a binary pass / fail to cut variance, and sample on a two-dimensional grid of file format × media composition, which cut the evaluation workload by 75%.
Latency for a generative service cannot be one number. Split it at least into TTFT (time to first token, which decides whether it feels responsive) and TPOT (time per output token, which decides whether the words keep up with reading — a comfortable reading pace is on the order of a dozen or so words per second). That is why streaming is the default in almost every chat product: it compresses perceived waiting from total duration down to TTFT.
The three serving tricks all revolve around tokens: continuous batching (splice decode steps from different requests into one batch so the GPU never idles), KV and prefix caching (compute the shared system prompt once), and quantization and distillation (trade a smaller model for a lower unit price per token). The open-source engine vLLM puts the first two straight into its pitch: PagedAttention for "efficient management of attention key and value memory", plus "continuous batching of incoming requests, chunked prefill, prefix caching".
What monitoring watches is not just 5xx either: quality drift (judge scores sliding slowly), cost drift (mean output length creeping up), guardrail hit rate and user rejection rate (retries, thumbs-down).
Table 1 · Where capability comes from: the four-rung ladder (timelines and costs are common industry magnitudes, not figures from the book)
| Prompt engineering | RAG | Fine-tuning / PEFT | Continued or full pretraining | |
|---|---|---|---|---|
| Cures what | Under-specified task, format demands | Knowledge gap: doesn't know your facts, or they changed | Behaviour gap: tone, format, procedure adherence | Domain language itself out of distribution |
| Time to first try | Hours | Days to weeks | Weeks | Months |
| What you need | Dozens of examples | A corpus, an index, retrieval and reranking | Hundreds to tens of thousands of clean samples | TB-scale corpora, thousand-GPU-scale compute |
| Price paid | Weakest control; long prompts get costly and brittle | An extra retrieval hop per request; longer context inflates the bill | You now maintain a training and versioning pipeline; a new base model resets it | Not economic for most teams |
Table 2 · Three evaluation routes: who judges, and how much you can afford to judge
| Automatic metrics | LLM-as-judge | Human review | |
|---|---|---|---|
| How it scores | Against a reference (BLEU / ROUGE / FID / perplexity) | A strong model applies a rubric case by case | People rate or pick side by side |
| Cost per case | Near zero | One model call | Tens of seconds to minutes of human time |
| Scale | Full set, every commit | Tens of thousands, in minutes | Sampling only |
| Catches | Broken formatting, obvious regressions | Relevance, faithfulness, instruction following | Subtle factual errors and experience differences |
| Misses | Right answer, different wording scores low | Its own length, position and same-family biases | Inter-rater disagreement — and the price |
The value of this chapter is a shared vocabulary across products: whether you are building completion, translation, chat, RAG question answering or text-to-image, it comes down to the same handful of questions — what are the latency and cost budgets, which rung of the ladder supplies the capability, who judges quality, and how does breakage become visible. It also maps onto how real teams divide the work: retrieval and indexing, inference serving (engines like vLLM and TensorRT-LLM), evaluation platforms, and safety guardrails are four separate jobs today.
25%, end-to-end latency down 38%, TTFT improved about 18%, evaluation workload down 75%. Confirms that designing the evaluation is where much of the engineering goes. Google Cloud Blog, "How KDDI built Buffmee" ↗1000 tokens in the system prompt is paid on every request; at a million daily users that writes your architectural decision straight onto the invoice.① The spine of the book: seven steps — requirements, frame the generative task, data prep, model development, evaluation, deploy and serve, monitor and iterate — and it is a loop, not a line.
② Three root differences from discriminative systems: no answer key, cost per token, fluent failure.
③ Output length is simultaneously cost and latency — the hard constraint running through the book.
④ Feature engineering exits, replaced by data curation (training side) and context construction (inference side); the context window is the new feature budget.
⑤ Step one nails four competing budgets: latency, cost, quality, safety. Before those, model selection talk is empty.
⑥ The four-rung ladder: prompting → RAG → fine-tuning → pretraining. Knowledge gap takes RAG, behaviour gap takes fine-tuning; reversing them is the expensive mistake.
⑦ Layer the evaluation: automatic metrics on everything, the model judge as regression, humans sampling to calibrate the judge, A/B or side-by-side battles online.
⑧ Split latency into TTFT and TPOT; the three serving levers are continuous batching, KV/prefix caching, and quantization or distillation.
⑨ Because failure throws no error, a generative system must build its own visibility layer: citations, groundedness checks, guardrail hit rate, user rejection rate.