CONTENTS
A method for designing AI systems
When you face a blank whiteboard and the prompt "design an AI system that does X," it's tempting to start drawing boxes: vector database, agent, model. Experienced designers don't. They start by pinning down what "good" means, because in AI systems that's the hardest question and everything else follows from it.
This chapter gives you a repeatable method. It borrows from classic system design interviews, from Ali Aminian and Hao Sheng's Generative AI System Design Interview, and mostly from how the practitioners in this book describe their actual work.
Step 1: Pin down the task and the quality bar
Start with three questions.
What exactly is the input and the output? "Answer support questions" is vague. "Given a customer's message and their account, produce a reply that either answers from our docs, takes one of five account actions, or hands off to a human" is designable.
What does a good output look like, and who decides? Write five real examples of excellent outputs and five of unacceptable ones. If you can't, you don't understand the task yet, and no architecture will save you. Hamel Husain and Shreya Shankar recommend naming one domain expert as the final judge of quality (they call this person the "benevolent dictator"), because committees produce vague criteria.
What does a mistake cost? A wrong movie recommendation costs nothing. A wrong drug interaction costs a lot. A wrong refund costs money. The cost of an error decides how much verification, human review and restriction you need, which decides most of the architecture.
Key insight: The cost of an error, not the difficulty of the task, is the biggest single driver of AI system architecture. Low-cost errors let you ship an autonomous system early and improve it from feedback. High-cost errors push you toward narrow workflows, verification and human approval.
Step 2: Set budgets
Every AI system lives inside three budgets, and you should write numbers for each before drawing anything.
Latency. How long can the user wait? A code completion must appear in a few hundred milliseconds. A chat reply should start streaming within a second or two. A research report can take minutes, and a nightly batch job can take hours. Latency budget decides whether you can afford multi-step reasoning, retrieval rounds or a second model checking the first.
Cost. What can one request cost and still make business sense? Work it out from the product: if a support conversation saves $5 of human time, spending $0.50 on it is fine and $8 is not.
Quality. What's the minimum acceptable pass rate on your evals, and on which failure types? "95% of answers correct, zero answers that leak another customer's data" is a quality budget.
These three trade against each other constantly. A bigger model raises quality and cost. Retrieval raises quality and latency. Caching cuts cost and latency but risks stale answers. Good design is choosing where on that surface to sit.
Step 3: Do the napkin math
Before you design, estimate. You need three formulas.
Tokens per request. Add up what goes in: system prompt, tool definitions, retrieved documents, conversation history, user message. Then estimate what comes out. As a rough rule for English, one token is about three quarters of a word.
Cost per request.
where is token count and is the price per million tokens. Output tokens typically cost several times more than input tokens.
Latency per request. For a single model call:
TTFT is time to first token: how long until the first token appears. TPOT is time per output token: the gap between tokens after that. Chapter 3 explains where those numbers come from; for now, know that TTFT grows with input length and TPOT is roughly fixed per model and server.
Here's a worked example. A RAG assistant sends a 1,500-token system prompt, 4,000 tokens of retrieved docs, 1,000 tokens of history and a 100-token question, and gets a 400-token answer. Suppose (illustrative prices) input costs $3 per million tokens and output costs $15 per million:
- Input: 6,600 tokens × $3 / 1M = $0.0198
- Output: 400 tokens × $15 / 1M = $0.006
- Total: about $0.026 per request
At 100,000 requests a day, that's about $2,600 a day, or roughly $950,000 a year. Notice what dominates: input tokens, because they're re-sent on every turn. That's why prompt caching (Chapter 12) matters so much: the first 1,500 tokens are identical on every request.
At 50 ms TPOT, the 400-token answer takes about 20 seconds to finish streaming. If your users won't wait that long, you need a faster model, a shorter answer, or both. You found that out with a pencil, before writing code.
Common confusion: People estimate cost from the output because that's what they see. In most production systems input tokens dominate, often by a wide margin. The Manus team reported an input-to-output ratio around 100:1 for their agent, because every step re-sends the whole history.
Step 4: Choose the lightest architecture that can work
Now draw boxes, but start from the left of this spectrum and move right only when you have to.
simpler, cheaper, more predictable more flexible, costlier, riskier
◄─────────────────────────────────────────────────────────────────────────────────────────►
no LLM ─► single call ─► call + retrieval ─► fixed workflow ─► agent ─► multi-agent system
Anthropic's Erik Schluntz and Barry Zhang make this the central advice of "Building effective agents": find "the simplest solution possible," and only increase complexity when it measurably improves outcomes. Many problems that look like they need an agent are a single well-built prompt plus retrieval. Many that look like they need multiple agents need one agent with better tools.
For each step to the right, ask: what specific failure of the simpler design does this fix, and how will I measure that it fixed it?
Step 5: Design the data flow, then the failure modes
Trace one request end to end. Where does each piece of context come from? What's computed live versus precomputed? What's stored after the request (logs, memory, feedback)?
Then walk the failure modes, the same way you'd ask "what if this database is down" in classic design, but with AI-specific failures added:
- The model returns malformed output.
- The model returns well-formed but wrong output.
- Retrieval returns nothing, or the wrong thing.
- A tool call fails, times out, or succeeds twice.
- The provider rate-limits you or goes down.
- Input contains instructions from an attacker.
- The conversation grows past the context window.
- The model behind your alias changes.
For each one, decide: detect it how, and recover how?
Step 6: Decide how you'll know it works
Finally, before building, design the evaluation and observability. What will you log? What's the first eval set (Chapter 9 says: start with real traces and error analysis, not a generic benchmark)? What metric would make you roll back a change? What feedback do users give you, explicitly or implicitly?
Teams that skip this step build systems they can't improve. Teams that do it first, as Husain puts it, can iterate quickly because they can see what's broken.
The method on one page
1. Task & quality bar input → output, good/bad examples, cost of an error, who judges
2. Budgets latency (p50/p95), cost per request, minimum quality
3. Napkin math tokens in/out, cost/request, cost/day, latency
4. Lightest design no LLM → call → +retrieval → workflow → agent → multi-agent
5. Data flow & failures trace one request; for each failure: detect, recover
6. Measurement traces, eval set, rollback metric, feedback loop
Key takeaways
- Start with what "good" means and what a mistake costs. That decides most of the architecture.
- Write down latency, cost and quality budgets before drawing anything.
- Do napkin math. Input tokens usually dominate cost; output length usually dominates latency.
- Start at the simple end of the spectrum and move right only to fix a measured failure.
- Walk AI-specific failure modes, and design evaluation before you build.
Exercises
- Run the six-step method on "an assistant that drafts replies to sales emails using our CRM." Write one page.
- Redo the napkin math above for a 20-turn conversation where history grows by 500 tokens per turn. What does the 20th turn cost? What does the whole conversation cost?
- Write five good and five bad example outputs for a feature you'd like to build. Note which bad ones are cheap mistakes and which are expensive.