Expert about 4 h
The picture
01
Client
web, API
02
Gateway
auth, limits, redaction
03
Orchestrator
workflow or agents
04
Models + tools + retrieval
capabilities
05
Guardrails
in and out
06
Telemetry + evals
the feedback loop
The picture
Client (web / API / chat)
│
▼
┌───────────────────────────── Edge / Gateway ─────────────────────────────┐
│ authN/Z · rate limits · size limits · PII redaction · input guardrails │
└───────────────────────────────────┬─────────────────────────────────────────┘
▼
┌───────────────────────────── Orchestrator ────────────────────────────────┐
│ router → workflow or agent loop · budgets (steps, tokens, $) · state/ckpt │
└───────┬──────────────────────┬──────────────────────┬───────────────────────┘
▼ ▼ ▼
Model gateway Retrieval layer Tool layer (least privilege)
(routing, fallback, (hybrid search, (read-only DB, APIs, MCP,
cache, budgets) rerank, ACL filters) sandboxed code, approvals)
│ │ │
└──────────────────────┴──────────┬───────────┘
▼
Output guardrails (schema, PII, grounding, policy)
▼
Response
───────────────────────────────────────────────────────────────────────────
Cross-cutting: tracing + cost metrics · prompt/model/index versions
eval suite (offline + online) · feedback → golden set
secrets · audit log · kill switch
Responsibilities, one line each
- Gateway: the first line of defence and the place to enforce limits, so nothing downstream has to.
- Orchestrator: owns control flow, budgets and state. Prefer the simplest shape that works: a single call, then a workflow, then an agent.
- Model gateway: one place for keys, routing, fallbacks, caching and cost accounting.
- Retrieval: applies access control at query time; returns citations.
- Tools: each with its own narrow credentials, validation and approval policy.
- Guardrails: enforced in code on both sides of the model, because the model itself is not a security boundary.
- Telemetry and evals: the feedback loop that lets you change anything safely.
Failure domains: what does the user see?
For each dependency, decide the degraded behaviour in advance.
- Model provider down or slow: fall back to a second provider or smaller model; if none, a clear message, never a hang.
- Retrieval down: answer without documents and say so, or refuse; never invent sources.
- A tool fails: return a typed error to the model for recovery; cap retries; surface partial results.
- Guardrail service down: fail closed for high-risk paths, fail open only where the risk is low and you have decided so explicitly.
- Budget exhausted: stop with an explanation.
Decisions to record
Use short architecture decision records: context, options considered, decision, consequences. For example:
ADR-007: Use a workflow, not a free-form agent, for invoice triage
Context: Steps are known; accuracy and cost predictability matter more than flexibility.
Options: (a) single agent with 6 tools (b) fixed 4-step workflow (c) multi-agent
Decision: (b). Route → extract → validate → (optional) human review.
Consequences: Lower variance and cost; adding a new document type needs a code change, not a prompt change.
Revisit when: more than 30% of cases fall outside the workflow's branches.
Build versus buy
A framework, a managed agent service, a vector database or an evaluation platform each save time and add coupling. Decide with three questions: how differentiating is this?, how painful is migration later?, and what do we lose in visibility and control? Keep domain logic (prompts, schemas, evals, policies) in your repository whichever you choose.
Scaling considerations
- Statelessness: keep orchestrators stateless with state in a store, so they scale horizontally and survive restarts.
- Queues for bursts and long jobs; backpressure so overload degrades gracefully.
- Multi-tenancy: isolate data, rate limits and budgets per tenant.
- Regional and data-residency needs affect model and storage choices.
Common mistakes
- No explicit degraded mode: the system hangs when a dependency slows down.
- Putting policy in the prompt that should be in code.
- A diagram nobody updates. Keep it in the repository with the ADRs.
Exercises
- Draw the architecture of your capstone and annotate the failure behaviour of each box.
- Write three ADRs for decisions you actually made in this pathway.
You are done when you can…
- Draw a reference architecture for a system you could ship, naming each component's responsibility
- Identify the failure domains and what happens to the user when each one fails
- Record three architecture decisions with context, options and consequences