Deployed Lab

Module 1 · Designing AI systems · Chapter 02 · Free

The reference architecture every AI product shares

19 min1 clickable picture1 hands-on lab1 predict, 2 quick quizzes, 5-question final quiz5-min video review
In 30 seconds

The picture: a restaurant. A dining room, a kitchen pass, one supplier door, a pantry, hands that cook, a memory of regulars, house rules, and someone tasting the food.

What this chapter gives you
The cold open

BrightCart is a made-up online retailer. Its first support assistant was two layers deep: a chat box wired straight to a model. Launch week, at an illustrative 900 chats a day:

Nothing here is a model problem. Each failure is a missing layer.

The plan for this chapter
  1. Walk one refund request through the picture.
  2. Layers 1 to 4: surface, orchestration, gateway, retrieval.
  3. Layers 5 to 8: tools, memory, guardrails, eval.
  4. Worked example: a 3 second latency budget.
  5. Lab: match eight problems to the layer that owns the fix.

Next: the picture, and one request walking through it.

Step 1: One request, eight layers

Think of the product as a building with eight floors. A request enters at the top, work happens on each floor, and the answer leaves the way it came in. Press Next and follow a customer asking "where is my refund?"

Where the picture breaks down:

The eight layer reference architecture A request flows from the user surface through guardrails, orchestration, memory, retrieval, the model gateway and tools, then back out, while eval and observability watch every layer. 1. User surfacechat, voice, API 2. Guardrailschecks in and out 3. Orchestrationruns the loop 4. Memory and statechat and task state 5. Retrieval and datadocs and fresh data 6. Model gatewayone door to models 7. Tools and actionssystems it can touch 8. Eval andobservabilitytraces, scores,golden sets, cost answer back out
  1. "Where is my refund?" arrives in the support chat widget. The surface handles typing, streaming and the session, nothing smarter.
  2. Input checks confirm sign-in and strip an account number the customer pasted, so raw secrets never reach the model.
  3. Your code starts the loop: identify the order, check its status, then answer. It owns routing, retries and step limits.
  4. State holds what the chat established: order 7719, bought 12 days ago, so nobody asks again.
  5. Retrieval pulls the current returns policy and refund timeline, fresh from the help centre, not model memory.
  6. One door picks the model, applies keys and limits, and logs tokens, so a vendor swap is a config change.
  7. The model asks for the order system. Your code calls it: refund issued two days ago, landing Friday. A fact, not a guess.
  8. Output guardrails confirm no other customer data is named. Trace, cost and a quality score are logged for eval.

Next: the first four layers, one by one.

Step 2: Layers 1 to 4, where the request takes shape

1. User surface. Job: where people and programs meet the product: chat, voice, a widget, or an API. Missing it: the design assumes one channel, so adding voice or a partner API later means rebuilding. Ask: which surfaces must this work on in year one, and what does each do to input?

2. Orchestration. Job: the code that runs the loop: routes requests, calls layers in order, retries failures, stops runaway work. Missing it: the prompt becomes the program, and nobody can say why a request took its path. Ask: which steps are fixed in code, and which does the model choose? Basics: agents and workflows.

3. Model gateway. Job: one door to every model: routing, keys, rate limits, timeouts and cost logs. Missing it: keys and model names scatter through the codebase, and switching vendor becomes a rewrite during an outage. Ask: if this model doubled in price tomorrow, what exactly would we change?

4. Retrieval and data. Job: brings in facts the model does not have: documents, indexes and fresh data such as prices. Missing it: the model answers from training memory, stale the day your policy or prices change. Ask: how fresh must each fact be, and who owns updating it? End to end: RAG end to end.

Next: layers 5 to 8, where answers become actions and evidence.

Step 3: Layers 5 to 8, action, memory, safety, proof

5. Tools and actions. Job: the systems the AI can touch: order lookup, refunds, calendars, tickets. Words become real-world effects here. Missing it: the assistant can only describe actions, or worse, claim it did them, like BrightCart's phantom refunds. Ask: which actions are read-only, and which change the world and need limits?

6. Memory and state. Job: holds the conversation, user facts, and task state across steps and visits. Missing it: every message starts from zero, so users repeat order numbers and long tasks lose their place. Ask: what do we remember, for how long, and what must we delete on request?

7. Guardrails and policy. Job: input and output checks, permissions, and human approval for risky actions. Missing it: private data flows to the model, harmful output flows out, and a $40 refund gets the same scrutiny as a $4,000 one. Ask: which actions need a human yes first, and what is blocked outright?

8. Eval and observability. Job: traces of every request, quality scores, golden test sets, and cost meters. Missing it: quality changes are invisible, so a bad model update ships and stays shipped. Ask: how would we know within a day if answers got 10 percent worse? More in Chapter 11, "The eval loop: the pattern that makes every other pattern safer", and evals.

Predict first:

With no golden set and no scored traces, "the model changed" and "our product got worse" look identical, and both are invisible until customers complain. Eval is the layer that turns a silent change into a number.

Next: the same eight layers, priced in milliseconds.

Step 4: Worked example, a 3 second latency budget

Budgets make layers concrete. All figures are illustrative. Target: the refund answer completes in 3,000 ms. Split it before you build (memory reads sit inside orchestration, gateway overhead inside the model call, eval runs after the answer, off the clock):

Check: 100 + 150 + 400 + 1,800 + 300 + 150 + 100 = 3,000 ms. The model is 1,800 / 3,000 = 60 percent of the budget, which is why Chapter 3 takes up latency next. More: latency, streaming and cost.

Now the model call overruns to 2,400 ms, 600 ms over. You must find 600 ms or break the target:

  1. Narrow retrieval to the top 3 passages instead of 8: saves about 150 ms.
  2. Run the tool lookup in parallel with retrieval instead of after it: saves about 300 ms of wall clock.
  3. Let the gateway route this simple status question to a smaller, faster model: saves about 150 ms.

150 + 300 + 150 = 600 ms. Budget restored, each cut naming its layer. Notice what you did not cut: guardrails. Speed bought by removing safety is a loan, not a saving.

Next: the lab. Eight problems, eight owners.

Step 5: Hands-on lab, match the problem to its layer

Why this exercise: in design reviews, the fastest skill is naming the owning layer. It turns "the AI is bad" into a fixable ticket.

Do this:

  1. On paper, sketch the eight layers for a product you know, using the checklist below (illustrative). Mark any layer you cannot describe: that blank is your first design task.
  2. Then do the matching exercise: eight problems, one per layer.
Layer checklist (illustrative)
[ ] Surface: which channels, year one?
[ ] Orchestration: fixed steps vs model-chosen?
[ ] Gateway: how do we swap models?
[ ] Retrieval: freshest fact, and its owner?
[ ] Tools: read-only vs world-changing?
[ ] Memory: what is kept, what is deletable?
[ ] Guardrails: what needs human approval?
[ ] Eval: golden set, traces, cost meter?

Lab: In design reviews, the fastest skill is naming the owning layer, because it turns a vague complaint like the AI is bad into a fixable ticket. This lab runs in your browser and needs JavaScript enabled.

What to notice
Field note, November 2026

In design reviews, a useful habit is drawing these eight boxes on a whiteboard before naming any product. Teams tend to find two or three boxes empty, and those empty boxes predict the first production incidents better than the model choice does. Layer names vary between teams; the jobs do not.

Mix-ups to avoid

Chapter quiz

Five questions. Score 70% or more to mark this chapter complete.

Review this chapter in 5 minutes

Watch the whole chapter recapped: the eight layers, one refund request walked through them all, and a 3 second latency budget split by layer.

Decision rule: for every failure or feature, name the layer that owns it before discussing solutions. If no layer owns it, that gap is the design problem.

Review

Glossary

User surface
Where users meet the product: chat, voice, embedded widget or API. Example: a support chat box.
Orchestration
Code that runs the loop: routing, ordering, retries and limits. Example: a status question takes a short path.
Model gateway
One door to all models holding keys, routing and limits. Example: swap models by changing one config.
Retrieval
Fetching facts and documents at answer time. Example: pulling today's returns policy. See also Chapter 5, "Retrieval patterns: RAG variants and when each one fits".
Tools and actions
Systems the AI can call to read or change the world. Example: an order lookup, or issuing a refund.
Memory and state
What the product keeps about the conversation, user and task. Example: the order number given two messages ago.
Guardrails
Checks and permissions enforced in code, in and out. Example: human approval before a large refund.
Golden set
A fixed set of questions with known good answers, scored on every change. Example: 100 support questions run nightly.
Trace
A record of one request across all layers: inputs, calls, timing, cost. Example: why one answer took 4 seconds.
Latency budget
A total time target split across layers before building. Example: 3,000 ms, with 1,800 ms for the model call.

Next: "Quality attributes: accuracy, latency, cost and safety pull against each other".