llm.guideChapter 34System Design Case Bank

System Design Case Bank

Four more system designs: a coding agent, an extraction pipeline, a voice line and a SaaS copilot.

Part 8: Capstones. 6 sections, about 15 minutes.

Coding agentcorrectness, judgedby testsExtractiona 99% accuracypromiseVoice lineunder a secondto speakSaaS copilotpermissionsacross tenantsthe casethe constraint that shapes the design
Coding agentcorrectness, judgedby testsExtractiona 99% accuracypromiseVoice lineunder a secondto speakSaaS copilotpermissionsacross tenants
The four cases, each paired with the constraint that decides its design. The components repeat from case to case; the constraint does not.

Chapter 33 designed one system in depth. This chapter works four more through the same five steps, faster, to show how a different dominant constraint changes the design: correctness for a coding agent, an accuracy guarantee for extraction, delay for voice, and permissions for a copilot inside someone else’s product.

Each case gives the numbers, a sketch, the ways it fails, the cost per task and what to leave out of a first version. All figures are computed from stated assumptions with the illustrative prices of section 28.2; treat them as the arithmetic to redo with your own constants, not as quotes.

34.1Using the case bank

Find the constraint that dominates, and let it shape everything else.

The five steps of section 33.1 apply to every case: the job and its numbers, capacity and cost, the sketch, deep dives where it can fail, and trade-offs with a plan. What changes is which step carries the weight. In every case below, one constraint dominates, and naming it early is most of what separates a strong design from a generic one.

Use each case in three ways. Read it once for the reasoning. Then cover the text, take only the brief, and work the five steps yourself before comparing. Finally, change one number, ten times the volume, a tighter latency target, a regulated customer, and ask which parts of the design move. The parts that move are the ones that depended on that number; a design in which nothing moves was not using its numbers.

Common take“Every AI system is RAG plus an agent, so the designs are the same.”

Sharper take“The components repeat; the dominant constraint doesn’t. Tests decide a coding agent, an accuracy guarantee decides extraction, delay decides voice and permissions decide a copilot. I name that constraint first.”

34.2A coding agent for a mid-size codebase

The tests are the specification, so the agent is only as good as the test suite.

The brief. A company with 150 engineers and a two-million-line codebase wants an agent that takes small, well-specified issues, bug fixes, dependency upgrades, test additions, and opens pull requests. About 400 tasks a day once adopted.

a task: about 30 steps (read, search, edit, run tests)
one step: 40,000 tokens of context, 80% cached; 800 tokens out
  40,000 × (0.8 × 0.1 + 0.2) × $3 ÷ 1M + 800 × $15 ÷ 1M ≈ $0.0456
a task ≈ $1.37  (without caching: $3.96)
400 tasks a day ≈ $547 a day, about $12,038 a month of 22 working days
the codebase: about 24 million tokens, so the agent searches it; it never reads it whole
Issuesmall, specifiedSandbox, fresh per taskSearch codeRead filesEditRun testsno production credentials; package mirror only;budget: steps, time and moneyPull requestCI, then a persontests, coverage,static analysis,secret scanning;human review
Figure 34.1 The coding agent’s only way out of its sandbox is a pull request, which faces the same checks as a human’s.

The design. Each task runs in a fresh sandbox (section 19.6): a container with a checkout of the repository, the build tools, the test suite and no production credentials, with network access limited to the package mirror. The agent works with search, file reading, editing and running tests (chapter 20 explains why search beats stuffing the context with files), within a budget of steps, time and money. Its only way out is a pull request, which goes through the same CI as human work, tests, static analysis and secret scanning (section 32.5), and a human review. Instructions checked into the repository give every run the conventions and commands (section 32.4).

How it fails. Code that passes weak tests and is wrong; flaky tests that the agent “fixes” by deleting assertions; changes that sprawl beyond the issue; dependencies that do not exist (section 32.5); instructions planted in an issue or a code comment (chapter 26). Each has a control: test coverage gates, a rule and a check against weakened assertions, a size limit on the diff, a dependency allow-list and treating issue text as data.

Cut from version one. Autonomous merging, tasks in parts of the codebase with poor tests, and anything touching authentication or payments. Measure with the team metrics of section 32.6: lead time, review wait and change failure rate on agent pull requests, not the number opened.

Common take“A coding agent needs the whole codebase in its context.”

Sharper take“It needs search, a sandbox and a good test suite. At about $1.40 a task with caching, cost is not the constraint; the tests are. Where the tests are weak, the agent doesn’t go.”

34.3A document-extraction pipeline with an accuracy SLA

A model alone cannot promise 99%; a model, validation rules and a review queue can.

The brief. A finance operations company processes 200,000 supplier invoices a month, about three pages each, and must extract twelve fields per invoice, supplier, dates, totals, tax, line items, into its accounting system. The contract promises 99% accuracy per field.

The arithmetic that shapes the design. Suppose the vision model (section 12.6) extracts each field correctly 97% of the time. All twelve fields of an invoice are then right only 69% of the time, and no prompt change closes a gap that size. The design adds checks that do not depend on the model: totals that must add up, dates that must be valid and in order, tax rates that must match the supplier’s country, suppliers that must exist in the master data. A field that fails a check sends its document to a person.

0%15%30%45%60%97.5%98.0%98.5%99.0%99.5%100.0%invoices sent to a personfield accuracy reaching the customerthe promise: 99%99.1%, 33% reviewed
0%15%30%45%60%97.5%98.0%98.5%99.0%99.5%100.0%invoices sent to a personfield accuracy reaching the customer
  • stricter or looser validation
  • the setting chosen
Figure 34.2 Computed from stated assumptions: 3% of fields wrong from the model, twelve fields per invoice, and checks that flag more correct fields as they are made stricter. Each point is one strictness setting.

Stricter checks catch more errors and also flag more correct fields, so the share of documents sent to people rises. In the computation, catching 70% of field errors brings field accuracy to 99.1%, just over the promise, and sends 33% of invoices to review. At an illustrative 40 cents a review and a cent a page for the model, that is about 16 cents an invoice, $26,019 a month of review against $6,000 of model calls. The people are the main cost, so the work that pays is improving the checks’ precision, not changing the model.

The design. Ingest and page images, extraction to a schema (section 11.4), validation in code, routing by result, a review interface that shows each flagged field beside the highlighted region of the page, and corrections fed back as labeled data (chapter 25). Accuracy is measured continuously by sampling auto-accepted invoices for human audit, since the SLA covers documents nobody reviewed.

Cut from version one. Line-item extraction for the rarest layouts (route those to review), automatic supplier creation, and fine-tuning until the correction data shows where the model is weakest.

Common take“We need a model that is 99% accurate.”

Sharper take“At 97% per field, only 69% of invoices are fully right. Validation in code catches most errors and sends about a third of invoices to people; we audit a sample of the rest, because the guarantee covers what nobody reviewed.”

34.4A voice support line at 10,000 calls a day

In voice, delay is part of correctness, so the latency budget is the design.

The brief. A utility company wants a voice agent for 10,000 calls a day: outage reports, bill questions, payment arrangements. Calls average four minutes; 12% of a day’s calls arrive in the busiest hour.

busiest hour: 10,000 × 12%              = 1,200 calls
concurrent calls (calls an hour × minutes ÷ 60) = 80; plan capacity for about 120
cost per minute: recognition $0.006 + synthesis $0.015 + model $0.012 + telephony $0.010 ≈ $0.043
a four-minute call ≈ $0.17; 10,000 calls ≈ $1,720 a day
Telephony,media serverTurndetection300 msRecognitionstreaming100 msModelfirst token300 msFirstsentence150 msSynthesisfirst audio120 msabout 970 ms from the caller stopping to the first audio, with stages overlappedTransfer to a personwith the transcript summarized, whenever askedread back numbers before acting; speak while tools run;pause recording for card details
Figure 34.3 The voice budget from section 22.5 applied to this line. Turn detection (orange) is the largest line and the cheapest to change.

The design. The cascade of chapter 22: telephony into a media server, streaming recognition with vocabulary hints for account numbers and street names, a language model with a lean prompt and few tools, streaming synthesis that starts on the first sentence. The budget above, about 970 ms to the first audio, is met by overlapping stages (section 22.7), not by a faster model; turn detection is the largest line and the cheapest to tune. Every tool call is covered by a spoken line, and barge-in follows section 22.6.

How it fails. Misheard numbers flowing into actions (read them back and confirm, or take them by keypad), silence during tool calls, callers who need a person and cannot get one, and card numbers spoken into recordings (pause recording and redact, section 22.10). Payment arrangements are an action with money attached: the agent proposes, the caller confirms what was heard, and limits apply in code.

Cut from version one. Payment arrangements (transfer to a person with a summary), languages beyond the top two, and outbound calls. Start with outage reports, which are frequent, structured and low-risk.

Common take“We’ll put our chatbot on the phone with speech recognition and synthesis.”

Sharper take“A voice turn has under a second to start speaking. The budget is turn detection, transcript, first token, first sentence and first audio, overlapped. Numbers are read back, tool calls are covered by speech, and at about 17 cents a call cost is not the hard part.”

34.5A copilot inside a B2B SaaS product

The copilot may never see more than the user could, in any tenant.

The brief. A project-management product with 2,000 customer companies and 150,000 seats wants an assistant that answers questions about a customer’s projects, summarizes status and, later, creates and updates tasks. About 15% of seats use it weekly, a dozen requests each.

active users: 150,000 × 15%              = 22,500
requests: 12 a week × 4.3 weeks × $0.02  ≈ $1.03 per active user a month
model cost ≈ $23,220 a month
sold as a $10 add-on to those users ≈ $225,000 a month, 90% after inference
  (check the heavy tail, section 31.2, before trusting the average)
User intenant ACopilot service: every step carries user and tenantRetrievaltenant partition, then theuser’s permission per itemProduct’s access ruleschecked at query time,not copiedModelanswers with citationsinto the productCacheskeyed by tenant and userActions through the product’s API, as the userthe product’s own authorization applies; every call loggedTenant Ba separate partition,no path from tenant A
Figure 34.4 Permissions decide this design. The highlighted step filters by tenant and checks each item against the product’s live access rules, so a revoked permission takes effect on the next request.

The design. The hard requirement is that the assistant sees exactly what the user can see. Every request carries the user’s identity and tenant; retrieval filters by tenant first and by the user’s permissions on each item, using the product’s own access rules rather than a copy of them that can drift; the index is partitioned by tenant; caches include the tenant and user in their keys (section 28.5); and actions go through the product’s API as that user, so the product’s existing authorization applies. Each answer cites the projects and tasks it drew on, linking into the product.

How it fails. A cached answer served across tenants; a permission revoked in the product but still present in the index; a shared document carrying an instruction that the copilot follows for another user (section 26.9); and an enterprise customer whose contract forbids sending its data to a particular provider (section 27.4). Each needs a test in the suite: cross-tenant and revoked-permission cases belong in every CI run, not only in a launch review.

Cut from version one. Write actions, which come next as drafts the user confirms (section 30.4); cross-project analytics, which need aggregation the retriever is bad at (section 15.7); and per-tenant fine-tuning.

Common take“We’ll index all the customer data and let the copilot search it.”

Sharper take“Retrieval filters by tenant and by the user’s permissions at query time, using the product’s own access rules, and actions go through the product’s API as that user. Cross-tenant and revoked-permission cases run in CI on every change.”

34.6What the cases share

Different constraints, the same habits.

CaseDominant constraintCost per taskThe control that matters mostLeft out of version one
Support assistant (chapter 33)Wrong-policy answersAbout 8.5 cents a conversationCurrent-version retrieval and gated actionsRefunds above $25 without approval
Coding agentCorrectness, judged by testsAbout $1.37 a taskSandbox, CI and human reviewAutonomous merging
ExtractionA 99% accuracy promiseAbout 16 cents an invoiceValidation in code and a review queueRare layouts, fine-tuning
Voice lineUnder a second to speakAbout $0.17 a callAn overlapped latency budgetPayments, outbound calls
SaaS copilotPermissions across tenantsAbout $1.03 a user a monthPermission filtering at query timeWrite actions

Read down the columns and the habits of this guide reappear. In every case the cost per task is small next to the value of the task, so cost is rarely the constraint, though it becomes one at scale (chapter 28). In every case the decisive control is ordinary code around the model: tests, validation rules, a latency budget, a permission check. And in every case version one is narrower than the brief, chosen so that it can be measured, trusted and widened on evidence.

That last habit is the one to carry out of this guide. A model makes a system capable; evals, a harness and a careful first version make it something people can rely on.

Common take“The model is the system.”

Sharper take“The model is one component. What makes each of these systems reliable is the code around it, tests, validation, budgets and permissions, and a first version narrow enough to measure.”

Key takeaways

  • Name the dominant constraint first; then change one number and check that the design moves.
  • Coding agent: sandbox, search, tests as the specification, pull requests through normal CI and review. About $1.37 a task with caching.
  • Extraction: 97% per field is only 69% of documents fully right. Validation in code plus a review queue reaches the promise; audit what nobody reviewed.
  • Voice: under a second to the first audio, met by overlapping stages and tuning turn detection, with numbers read back and tool calls covered by speech.
  • Copilot: the assistant sees exactly what the user sees, filtered at query time by the product’s own permissions, with cross-tenant tests in CI.
  • Across all cases, cost per task is small next to value, the decisive controls are ordinary code, and version one is narrow on purpose.

Check your understanding

  1. The extraction customer asks to raise the promise from 99% to 99.5% per field without a price increase. Using section 34.3, what changes and what does it cost?

    Answer outline

    With 3% model error per field, 99.5% needs about 83% of errors caught instead of 70%. Stricter checks also flag more correct fields, so the review share rises from about a third toward a half of invoices in the computation, and review is the dominant cost. Options: improve the checks’ precision so they flag fewer correct fields, improve the model on the weakest fields using correction data (fine-tuning becomes worth testing here), or price the higher promise. The audit sample must also grow, since a smaller error rate takes more samples to verify.

  2. The voice line’s first audio averages 1.6 seconds in production against a 1-second budget, and the model’s dashboards show first tokens in 300 ms. Where is the time?

    Answer outline

    Outside the model (section 22.5): most likely turn detection waiting too long for the caller to finish, synthesis waiting for the whole answer rather than the first sentence, or stages running one after another instead of overlapping. Measure each line of the budget separately from traces, starting with the end-of-speech wait and the time until synthesis starts. Also check the prompt length, since a large tool list or retrieved context delays the first token on some turns.

  3. A copilot customer reports that a user who was removed from a project last week still got an answer summarizing that project’s tasks. What failed, and what prevents it?

    Answer outline

    Permissions were checked against a copy that had not caught up, in the index metadata or a cache, instead of against the product’s own access rules at query time (section 34.5). Fix: check each retrieved item against the product’s authorization when answering, include the user in cache keys and invalidate on permission changes, and propagate revocations to the index quickly. Add a revoked-permission test to CI, review whether other users were affected using the traces, and handle it as a security incident with the customer.

Further reading

  • Every earlier chapter’s reading list: each case draws on several of them.
  • Chip Huyen, AI Engineering (O’Reilly, 2025), chapter 10: architecture and user feedback.
  • Chip Huyen, Designing Machine Learning Systems (O’Reilly, 2022): data, deployment and monitoring for systems with models inside.
  • Martin Kleppmann, Designing Data-Intensive Applications: the storage, consistency and streaming foundations under every design here.

↑↓ to move↵ to openesc to close