ADRs and C4 Diagrams: Write Down the Why, Draw the What at Four Zoom Levels
A new engineer asks why the AI assistant sits behind a queue and why embeddings live in a separate vector store, and the person who decided has left. One ADR per decision, superseded rather than edited, plus C4 diagrams at three zoom levels whose boxes point to those ADRs.
What you will learn
- Write a one-page ADR with context, decision, alternatives and two-sided consequences
- Use ADR status (proposed, accepted, superseded) and keep records in docs/adr
- Draw an AI support app at C4 levels 1 to 3, one level per diagram
- Link diagram boxes to the ADRs that put them there
Before you start
- What a queue and a vector store are
- The Pattern Atlas
Picture a support-ticket app. Customers open tickets, agents answer them, and an AI assistant suggests replies to the agents. A new engineer joins and asks two fair questions on day one. Why is the AI assistant behind a queue? Why are the embeddings in a separate vector store, not in the main database?
The answer she gets is "ask Sam". Sam decided all of that, and Sam left the team last spring. So she looks at the whiteboard diagram instead: fourteen boxes, some people, some servers, some classes, and arrows with no labels. It tells her nothing.
Two things are missing: the reason behind each decision, and a picture she can read. Two small tools fix that. The idea in one line: draw the what, and write down the why.
- The architecture decision record (ADR) answers why.
- The C4 model answers what is in the system and where each part sits.
They work together: every important box on a diagram can point to the decision that put it there.
One decision, one page
An ADR is one short page about one decision. The lecture's kit keeps a template in docs/adr/0000-template.md:
# ADR-NNNN: <short decision title>
Status: Proposed | Accepted | Deprecated |
Superseded by ADR-NNNN
Date: <day the status last changed>
## Context
What forces us to decide now? Facts, limits,
numbers we measured.
## Decision
We will ... (one or two sentences, active voice).
## Alternatives considered
- Option A - why not.
- Option B - why not.
## Consequences
+ What gets easier.
- What gets harder, and what we must now watch.
Here it is filled in for the queue:
# ADR-0003: Run AI reply suggestions on a queue
Status: Accepted
## Context
A model call can take several seconds and the
provider limits requests per minute. Agents
need the ticket page to open at once.
## Decision
The API saves the ticket and puts a job on a
queue. A worker calls the model and stores the
suggestion; the page shows it when ready.
## Alternatives considered
- Call the model inside the request - the page
waits on the slowest call.
## Consequences
+ The page stays fast; failed calls are retried.
- One more moving part to run and monitor.
- The suggestion appears a few seconds later.
Consequences cut both ways
Consequences is the field people skip, and it's the most useful one. The good side: the page stays fast, and failed calls are retried. The cost: one more moving part to run and monitor, and the suggestion appears a few seconds later.
An ADR that lists only upsides is a sales pitch, not a record. Writing down the cost is what makes it honest, and it tells the next person exactly what to watch. For a deeper worked ADR, with options, residual risk and the evidence a build must produce, see the ADR for a Claude system.
Status, and where ADRs live
Every ADR has a status. It starts as proposed while the team discusses it. When the team agrees, it becomes accepted, and from then on you don't edit it.
So what happens when a decision changes? The team first kept embeddings in Postgres, because one database was simpler:
# ADR-0002: Keep embeddings in Postgres
Status: Superseded by ADR-0004
## Context
The assistant searches past tickets by meaning.
We already run Postgres for tickets.
## Decision
We will store embeddings in Postgres with the
pgvector extension.
## Alternatives considered
- A separate vector database - one more system
to run for a small team.
## Consequences
+ One database to back up and secure.
- Search load shares the ticket database.
Later, search became the heaviest query and slowed the ticket pages. Instead of editing 0002, the team wrote a new record and marked the old one as superseded:
# ADR-0004: Move embeddings to a vector store
Status: Accepted
Supersedes: ADR-0002
## Context
Similarity search became the heaviest query on
the ticket database and slowed ticket pages.
## Decision
We will move embeddings to a managed vector
store. Tickets stay in Postgres.
## Consequences
+ Ticket pages no longer wait on search load.
- Two stores to keep in step when tickets change.
Notice that 0002 predicted its own problem: "search load shares the ticket database". The history stays readable.
ADRs live in the repository, next to the code, in a docs/adr folder: numbered files, reviewed in pull requests like any other change.
Not every choice needs one. Ask three questions: is it hard to reverse? Is it costly? Would it surprise a new engineer? A small library pick fails all three, so no ADR. The queue passes, so it gets one.
C4 is a zoom
Think of a map app. The whole country is level 1, the system context. Zoom into a city: level 2, containers. A street: level 3, components. One building: level 4, the code. Level 4 is classes and functions, and your IDE can already show that, so most teams draw three levels and leave the fourth to the tools.
Level 1: system context
The whole system is a single box with nothing inside yet. Around it: the customer, who opens tickets; the support agent, who answers them; an email service, to send the emails; and the LLM provider, which is asked for reply suggestions. A manager, a customer, anyone at all can read this one.
Level 2: containers
Zoom into the system box and it opens up: a web app in the browser, an API server, a database, a queue, a worker and a vector store. Follow one suggestion. The web app calls the API server over HTTPS. The API server saves the ticket and puts a job on the queue. The worker takes the job, searches the vector store for similar tickets, and calls the LLM provider. Then the worker saves the suggestion in the database, and the agent sees it.
Be careful with one word. A container here means something that runs and can be deployed on its own. It might be a Docker container, but it doesn't have to be. This level is for developers and for the people who run the system.
Level 3: components
Zoom once more, into the API server. Ticket routes call the ticket service, which uses the ticket repository to reach the database. Next to it, the suggestion publisher, which the ticket service uses to put jobs on the queue. Below this sits level 4, the code, left to the IDE and drawn only for a part that's really tricky.
The kit's docs/c4/README.md writes all three levels as text:
## Level 2 - Containers (for developers, ops; see ADR-0003, ADR-0004)
- Web app (browser) -> API server: HTTPS/JSON
- API server -> Database (Postgres): SQL
- API server -> Queue: puts suggestion job
- Worker <- Queue: takes job
- Worker -> LLM provider: HTTPS
- Worker -> Vector store: similarity search
- Worker -> Database: saves suggestion
## Level 3 - Components (inside the API server)
- Ticket routes -> Ticket service
- Ticket service -> Ticket repository -> Database
- Ticket service -> Suggestion publisher -> Queue
Four rules for any diagram
- One level per diagram. Don't mix people, servers and classes in one picture.
- Every box has a name, a type and a one-line job.
- Every arrow has a direction and a label: what it carries, like "puts suggestion job".
- A key, so colours and shapes mean the same thing to everyone.
Same system as the whiteboard, but now a new person can read it in a minute.
The diagram meets the decision
On the containers diagram, the queue and the worker carry a small tag, ADR-0003. The vector store carries ADR-0004. Back to our new engineer: why is the AI behind a queue, and why a separate vector store? Both answers are now one click away, and Sam doesn't need to be in the room.
Recap
| Tool | Answers | Rules |
|---|---|---|
| ADR | Why | One decision per page; consequences on both sides; never edit an accepted one, supersede it; keep them in docs/adr |
| C4 | What and where | Four zoom levels, usually draw three; one level per diagram; named boxes, labelled arrows, a key |
Let the boxes point to their ADRs. Draw the what, and write down the why.
Try it yourself
Pick one decision in a project you work on that is hard to reverse. Write its ADR with at least one minus line under consequences, then draw the level 2 container diagram and tag the box that decision created.
Related course on Udemy
The Python Architect Masterclass: Full Stack to AI Engineer
Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)Related posts
Fallback Models for an LLM App: A Chain That Checks Region and Fit, Flags Degraded Answers and Gets Rehearsed
When the main model goes down, the backup has to be allowed to take the data, able to read the whole request and tested before the bad day. A simulated four-model chain for an EU customer: a 6,000-token request lands on mid-eu, flagged degraded; a 10,000-token request is served by nobody, on purpose.
Back Pressure for LLM Traffic: Bound the Queue, Give Chat Its Own Lane, Count Tokens, Cancel When the Caller Leaves
A bulk upload buries the chat. In a small simulation, one shared queue grows to 199 waiting and the middle chat answer takes 80.2 s. A bound plus a chat lane brings it to 0.35 s while 178 bulk jobs are told to retry in 10 s, and cancelling abandoned calls saves 21,000 wasted tokens.
Load Balancing LLM Traffic: Count the Work, Weigh the Prefix Cache, Check Real Health, Drain Before Deploys
Six GPU replicas, two at 95% and four at 30%: round robin counts requests, and requests aren't equal. In a small simulation, least outstanding requests cuts p95 from 6.52 s to 3.05 s, prefix affinity lifts cache hits to 95% but pushes p95 to 11.45 s, a real health check takes errors from 48 to 2, and draining cuts 0 answers instead of 4.
A Message Queue for Document Ingestion: At Least Once, Leases, an Idempotent Consumer and a Dead Letter Queue
A queue doesn't lose a document, but it can hand one out twice. In a small simulation, a worker crash makes document two go from 3 to 6 chunks and the index holds 11 when the documents hold 8. An idempotent consumer brings it back to 8 with the same two deliveries, and a limit of three tries moves a poison file to a dead letter queue.
