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.

  1. 01Basic LLM appPrompt + model
  2. 02RAG+ retrieval for grounding
  3. 03Agent+ tools and a loop
  4. 04Multi-agent+ specialists and a supervisor
  5. 05Workflow pipelines+ durable, scheduled, audited
Most successful products stop at stage 2 or 3.

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.

  1. 01IngestParse, clean, chunk
  2. 02Embed + indexVectors + keywords
  3. 03RetrieveHybrid search, top-k
  4. 04RerankBest few chunks
  5. 05GenerateAnswer with citations
A production RAG pipeline. Most quality problems are retrieval problems, not generation problems.
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:

FrontendStreaming responses, citations, conversation state, feedback buttons, graceful errors
APIAuthentication, authorization, rate limits, input validation, request ids
OrchestrationPrompt templates, routing, tool calls, retries, guardrails, output validation
RetrievalChunking, embeddings, hybrid search, reranking, metadata filters, access control
ModelsModel choice per task, gateway, fallbacks, structured output
ToolsAPIs, databases, code execution - sandboxed and permissioned
Infra · security · observability · evalsUnderneath everything: secrets, isolation, tracing, metrics, test suites

How to run the interview#

  1. 01User needsWho, what task, success metric
  2. 02Request pathTrace one request end to end
  3. 03Data & contextWhere facts come from; freshness; permissions
  4. 04Trade-offsQuality vs latency vs cost
  5. 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#

ConcernRule of thumb
Chunk sizeStart around 300-800 tokens with some overlap; tune on your eval set
RetrievalRetrieve ~20-50 candidates, rerank to the best ~3-8
LatencyUsers feel streaming start (time-to-first-token) far more than total time
CostInput tokens usually dominate RAG cost - retrieve less, cache prefixes
Model choiceSmallest model that passes your evals, per task - not one model for everything

7 AI design patterns for interviews#

1

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)?

2

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.

3

Caching

Exact-match cache for repeated requests, semantic cache for near-duplicates (with a similarity threshold), and provider prompt caching for long shared prefixes.

4

Guardrails

Input checks (injection, PII, off-topic) and output checks (policy, grounding, format). Fail closed on high-risk actions.

5

User feedback loops

Thumbs, edits, and escalations become labeled data: mine failures into test cases, and improve prompts or retrieval where users struggle.

6

Agentic evals

Evaluate trajectories, not just final answers: right tools, right order, no unnecessary steps, task success rate, cost per task.

7

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:

MetricQuestion it answers
Context recall / precisionDid retrieval find the needed chunks - and not much else?
FaithfulnessIs every claim in the answer supported by the retrieved context?
Answer relevanceDoes the answer address the question asked?
Task successDid 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

Further reading

Search Data Science After Dark

Search across prompts, models, papers, guides, and library topics.