How to solve any AI system design problem, with case studies

A repeatable eight-step method for AI design questions, from requirements to monitoring, followed by three worked designs: a support assistant, a coding assistant, and a real-time voice agent. Use it for interviews, design reviews, and your own projects.

The method in 60 seconds

  • Eight steps: requirements, AI objective, data, architecture, model and prompts, evaluation, deployment, monitoring.
  • Start with the user and the cost of a wrong answer, not with the model.
  • Choose the least freedom that works: a prompt before retrieval, retrieval before an agent, an agent before training.
  • State numbers: tokens per request, requests per second, latency target, and cost per request.
  • Always cover the failure cases: wrong answer, outage, attack, and privacy.

The eight steps

Work through the steps in order, and return to earlier ones when you learn something.

Step 1: Requirements

Ask who the users are, what they are trying to do, and what a good result looks like. Then ask the questions that are specific to AI.

  • Cost of a wrong answer: an annoyance, a lost customer, or a legal problem? This sets how much checking you need.
  • Latency expectations: chat feels fine with a first word in about a second; a voice agent needs far less; a nightly report can take hours.
  • Scale: users, requests per day, peak rate, and typical input and output size.
  • Data: where the knowledge lives, how often it changes, and who may see what.
  • Constraints: budget per request, regions, compliance, and whether data may leave your network.

Step 2: AI objective

Translate the product goal into a task a model can do, and decide how success will be scored. 'Help customers with returns' becomes 'classify the question, find the policy passage, and write a grounded answer that cites it'. Decide early whether a model is needed at all: a rules engine or a search page may solve part of the problem more reliably.

Step 3: Data preparation

List the data sources, and for each decide how it will be parsed, cleaned, chunked, and kept fresh, who may read it, and how updates reach the index. Also decide what evaluation data you will build: realistic questions with known good answers. Many designs fail here because the data is messy, stale, or not permissioned.

Step 4: Architecture

Now draw the system. Start with the simplest design that could work, and add a block only when a requirement forces it.

NeedStart withAdd when
Answers from documentsRetrieval plus a grounded promptHybrid search, reranking, or graph retrieval when measured misses justify it
Live data or actionsTool calling with a few well-defined toolsAn agent loop when the next step depends on the last result
Several distinct task typesA router in front of specialised promptsA supervisor when sub-tasks are decided at run time
Long conversationsA sliding window with a summaryLong-term memory when users repeat preferences
High traffic or costA cache and a smaller model for easy requestsA gateway, batching, and self-hosting at steady volume
Sensitive data or actionsInput and output checks, least privilegeConfirmation steps and red-team tests

Step 5: Model selection and prompting

Choose the smallest model that meets your quality bar on your own evaluation set. Write the prompt as a clear specification: role, task, allowed sources, output format, and what to do when the answer is not available. Use structured output where a program reads the result. Fine-tuning comes last, and only after measurement shows the gap.

Step 6: Evaluation

Define the metrics before you build: retrieval recall, answer faithfulness, task success, refusal accuracy, latency, and cost. Build the evaluation set, run it on every change, and set a release gate. Plan human review for a sample, and a way to calibrate any judge model.

Step 7: Deployment and serving

Decide hosted or self-hosted, how the system scales, how long tasks run asynchronously, and how failures are handled: timeouts, retries, fallbacks, and graceful degradation. Roll out gradually, and keep the previous version ready to restore.

Step 8: Monitoring

Trace every request with its prompt version, retrieved context, tool calls, tokens, latency, and cost. Watch quality signals, cost per feature, error rates, and drift. Turn real failures into new evaluation cases, and feed what you learn back into the requirements.

Case study 1: a customer support assistant

This is a design exercise built from first principles. It is not a description of any company's product.

Requirements

  • A support assistant for an online shop, answering questions about orders, returns, and products.
  • 50,000 users a day, about six questions each, and peaks at five times the average.
  • A wrong answer about a refund can cost money, so answers must be grounded and cite the policy.
  • First word within about two seconds; the full answer within ten.
  • Customer data is personal, and staff must be able to see the reasoning of any answer.

Design

  • Gateway: authentication, per-user rate limits in tokens, an exact cache for common policy questions, and a trace on every call.
  • Router: a small model classifies the question as order, policy, product, or other.
  • Tools: order lookup (read-only) and a refund request tool that requires customer confirmation and an idempotency key.
  • Retrieval: hybrid search over policies and product pages, with metadata for region and version and a reranker for the top results.
  • Generation: a mid-sized model answers only from the order data and the retrieved passages, in a fixed format with citations, and says so when it cannot answer.
  • Guardrails: an output check for format, personal data, and unsupported promises; injection defences for text from product reviews and emails.
  • Escalation: low confidence, a refusal, or an angry customer hands over to a person with the full trace.

Numbers

Using the assumptions above and about 800 input and 300 output tokens per question, the daily load is about 240 million input and 90 million output tokens. Averaged over a day, that is roughly a thousand output tokens a second, and about five thousand at peak. A cache hit rate of even 20 percent on policy questions, a small model for the router, and shared prompt prefixes would cut the cost meaningfully. These are estimates to replace with measurements from a pilot.

Risks and answers

RiskMitigation
Wrong refund answerGrounding check that can refuse; cite the policy version; escalate when unsure
Stale policyIndex freshness tracked per document; cache keyed by policy version
Prompt injection through reviews or emailsMark untrusted text; no write tools in the same context; confirmation before refunds
Provider outageFallback model and a simple FAQ path; circuit breaker
Cost spikePer-user and per-day budgets; shorter default answers; cost metrics per feature

Case study 2: a coding assistant

This is also a first-principles design exercise. It describes a plausible architecture, not the internals of any specific tool.

Requirements

  • An assistant inside a code editor that answers questions about a repository and makes multi-file edits.
  • It must work on repositories from small to very large, and respect which files a developer may share with a model.
  • Suggestions must be fast to be useful; larger edits may take a minute.
  • Edits must be reviewable and reversible; running commands must be safe.

Design

  • Indexing: parse the repository into files, functions, and symbols; chunk along code structure; build a vector index and a keyword index, and keep them updated as files change.
  • Retrieval: combine the cursor context, symbol references, and hybrid search to select a small, relevant set of snippets. Code questions are often about exact names, so keyword search matters.
  • Two speeds: a small, fast model for inline completions with a strict latency budget, and a larger model with an agent loop for multi-file tasks.
  • Agent tools: read file, search code, edit file, run tests, and run a restricted shell. Edits are proposed as diffs and applied only when accepted.
  • Feedback from tests: the agent runs the test suite and reads failures. A passing suite is the stopping signal, with a step budget.
  • Context management: compaction of long sessions, with a pinned section for the user's goal and constraints.
  • Safety: run commands in a sandbox with limited network and file access, deny destructive commands by default, and require approval for anything outside the project.

What to evaluate

Build a set of real tasks with tests: fix this bug, add this function, refactor this module. Score by whether the tests pass, how many steps it took, how many edits were rejected by the reviewer, and the cost. Also watch for the failure where the assistant changes a test to make it pass, which a review step should catch.

Risks and answers

RiskMitigation
Leaking private codePer-repository permissions; exclude secrets files; clear data-handling terms with the provider
A destructive commandSandbox, command allow-list, approval for risky actions
Edits that break other filesRun tests and a type check; show a diff before applying
Huge repositoriesIncremental indexing; retrieval instead of sending whole files
Slow completionsA small model, a short prompt, and caching of the shared prefix

Case study 3: a real-time voice agent

A third design exercise from first principles, for a phone line that books appointments.

Requirements

  • Callers book, move, or cancel appointments by speaking.
  • The first spoken reply should start within about a second after the caller stops speaking.
  • Callers interrupt, mumble, and speak over noise.
  • The call may be recorded only with consent, and personal data must be protected.

Design

  • Transport: a streaming connection that carries audio in both directions.
  • Pipeline: streaming speech recognition, a language model with a small tool set (check availability, book, cancel), and streaming speech synthesis, each passing partial output forward.
  • Turn-taking: voice activity detection with a short hang time, and barge-in that stops speech at once.
  • Short replies, with confirmation of key details by repeating them back.
  • Filler for slow tools: a short spoken note while a booking is checked.
  • Fallback: after repeated misunderstandings, offer a person or a callback.
  • Privacy: announce recording, store transcripts rather than audio where possible, redact personal data in logs, and set short retention.

What to evaluate

Measure word error rate on realistic phone audio, time to first spoken word, the share of calls that complete a booking, the share that hand over to a person, and how often the agent books the wrong slot. Test with accents, noise, and interruptions.

A checklist for any design

  • Did I state the cost of a wrong answer, and design the checks around it?
  • Did I estimate tokens, peak load, latency, and cost per request?
  • Did I start from the simplest architecture and justify each added block?
  • Where does each piece of data come from, and who may see it?
  • How will I know it works: what is in the evaluation set, and what is the release gate?
  • What happens when the model is wrong, slow, or unavailable?
  • What can an attacker make the system do, and what stops them?
  • What do I monitor, and how do failures become new test cases?

What this means for your role

Common mistakes

Further reading

A design is a set of decisions with reasons. Follow the steps, give the numbers, name the trade-offs, and say how you will find out you were wrong.

Search topics

↑↓ to move · Enter to open · Esc to close