Step 1 of 6
AI System Architecture
A GenAI app layer by layer, the evolution from a single LLM call to multi-agent workflows, and seven design patterns interviewers expect.
17 min read
A demo is a prompt and an API key. A product is everything around them: retrieval that finds the right facts, orchestration that handles failure, guardrails, evaluations, observability, and cost control. This guide shows how AI systems evolve from one call to a production architecture, gives you a layer-by-layer cheat sheet, and covers the seven design patterns interviewers expect you to know.
From basic LLM app to production#
Systems grow in stages. Don't jump ahead - each stage adds cost and complexity, so move up only when the previous stage demonstrably falls short.
- 01Basic LLM appPrompt + model
- 02RAG+ retrieval for grounding
- 03Agent+ tools and a loop
- 04Multi-agent+ specialists and a supervisor
- 05Workflow pipelines+ durable, scheduled, audited
1. Basic LLM app. A prompt template, a model call, and a UI. Fine for drafting and summarizing. Fails when it needs facts the model doesn't know - it will make them up.
2. RAG (retrieval-augmented generation). Retrieve relevant documents and put them in the prompt, with instructions to answer only from them and cite sources. This is the workhorse architecture for enterprise AI.
- 01IngestParse, clean, chunk
- 02Embed + indexVectors + keywords
- 03RetrieveHybrid search, top-k
- 04RerankBest few chunks
- 05GenerateAnswer with citations
- RAG
- Retrieval-Augmented Generation - retrieve relevant documents and include them in the prompt so the model answers from real sources instead of guessing.
- Hybrid search
- Combining keyword search (BM25) with vector/semantic search to get exact term matches and meaning-based matches together.
- Reranking
- A second-pass model that re-scores retrieved chunks by relevance, so only the best few reach the generator.
- Chunking
- Splitting documents into smaller pieces for indexing - chunk size and overlap affect what the retriever can find.
3. Agent. When answering requires actions or multi-step lookups the code can't predict, add tools and a loop (see Agent Fundamentals).
4. Multi-agent. When one agent juggles too many tools or roles, split into specialists under a supervisor.
5. Workflow pipelines. For long-running, scheduled, or business-critical processes, run agents inside a durable workflow engine with retries, checkpoints, and audit logs.
Around every stage, production adds the same cross-cutting pieces:
AI gateway
One entry point for all model calls: provider routing, fallbacks, rate limits, budgets, key management, logging.
Observability
Trace every request through retrieval, model calls, and tools, with token counts, latency, and cost.
Security
Auth, per-user data isolation in retrieval, prompt-injection defenses, PII handling, least-privilege tools.
Evaluation
Offline test sets run on every change; online metrics and user feedback in production.
Caching
Exact and semantic caches, plus provider prompt caching for long, repeated prefixes.
Deployment
Versioned prompts, models, and indexes; staged rollouts; instant rollback.
AI system design cheat sheet#
A GenAI application, layer by layer, with what each layer is responsible for:
How to run the interview#
- 01User needsWho, what task, success metric
- 02Request pathTrace one request end to end
- 03Data & contextWhere facts come from; freshness; permissions
- 04Trade-offsQuality vs latency vs cost
- 05Safety, evals, scaleFailure modes and how you'd know
Before you finish, check the design against six words: useful, grounded, safe, observable, fast, affordable. If you can't say how your design achieves each one, that's the next thing to discuss.
Numbers worth having in your head#
| Concern | Rule of thumb |
|---|---|
| Chunk size | Start around 300-800 tokens with some overlap; tune on your eval set |
| Retrieval | Retrieve ~20-50 candidates, rerank to the best ~3-8 |
| Latency | Users feel streaming start (time-to-first-token) far more than total time |
| Cost | Input tokens usually dominate RAG cost - retrieve less, cache prefixes |
| Model choice | Smallest model that passes your evals, per task - not one model for everything |
7 AI design patterns for interviews#
RAG
Ground answers in retrieved documents. Know chunking, hybrid search, reranking, citations, and how to debug: is the failure in retrieval (right chunk not found) or generation (found but misused)?
Fine-tuning
Change behavior, format, or style - not knowledge. Use when prompting plus RAG plateaus, or to shrink a task onto a cheaper model. Needs clean data and evals.
Caching
Exact-match cache for repeated requests, semantic cache for near-duplicates (with a similarity threshold), and provider prompt caching for long shared prefixes.
Guardrails
Input checks (injection, PII, off-topic) and output checks (policy, grounding, format). Fail closed on high-risk actions.
User feedback loops
Thumbs, edits, and escalations become labeled data: mine failures into test cases, and improve prompts or retrieval where users struggle.
Agentic evals
Evaluate trajectories, not just final answers: right tools, right order, no unnecessary steps, task success rate, cost per task.
LLM observability
Trace every step with inputs, outputs, tokens, latency, and cost; tag by prompt and model version; alert on regressions.
Evaluating RAG and LLM output#
You can't improve what you don't measure. The common metrics:
| Metric | Question it answers |
|---|---|
| Context recall / precision | Did retrieval find the needed chunks - and not much else? |
| Faithfulness | Is every claim in the answer supported by the retrieved context? |
| Answer relevance | Does the answer address the question asked? |
| Task success | Did the user (or agent) accomplish the goal? |
LLM-as-a-judge scales grading, but judges have known biases - favoring the first-listed answer, longer answers, and their own style. Mitigate by swapping answer order, using clear rubrics, and spot-checking against human labels.
Papers behind this guide
RAG: Retrieval-Augmented Generation
Combining retrieval systems with generative models - the architecture behind most enterprise AI apps today.
Meta AI, 2020
HyDE: Hypothetical Document Embeddings
Generate a fake answer, embed it, and retrieve real documents near it.
CMU / Waterloo, 2022
Ragas: Automated RAG Evaluation
Reference-free metrics for faithfulness, answer relevance, and context relevance.
2023
Judging LLM-as-a-Judge
When strong LLMs can grade other models - and the position, verbosity, and self-preference biases to watch.
LMSYS / UC Berkeley, 2023