Documenting Architecture: C4, ADRs, arc42
- Draw C4 context, container, component and code views for a payment platform
- Write an ADR that records context, options, decision and consequences — and know when to supersede it
- Use the arc42 outline to structure a complete architecture document
- Run an RFC / design-doc process that gets real feedback without stalling delivery
- Keep diagrams and decisions next to the code with diagrams-as-code
TL;DR
- Document for decisions and understanding, not for completeness. The test of a document is whether a new engineer, an auditor or an on-call SRE can act on it.
- C4 model (Simon Brown): four zoom levels — System Context, Container, Component, Code — plus deployment and dynamic views. Most teams need only context + container, kept current.
- ADRs (Michael Nygard): short, numbered, immutable records — context, decision, consequences — stored in the repo. Change your mind by superseding, never by editing history.
- arc42: a 12-section template for a full architecture description; use it as a checklist, fill only what earns its keep.
- RFC / design doc: write before you build anything expensive to reverse; circulate for asynchronous review; time-box; record the outcome as ADRs.
- Diagrams as code (Mermaid, PlantUML, Structurizr DSL): versioned, reviewable in PRs, diffable, never "the Visio file on someone's laptop".
Why it matters
Banks must document architecture: auditors and regulators ask for evidence of how systems handle customer data, how changes are approved, and how disaster recovery works. Architecture review boards expect an HLD before they approve a project. But most bank documentation is a 120-page Word file written once for approval and never updated — useless to the engineers and misleading to the auditors.
E-commerce companies have the opposite problem: fast teams, little documentation, and tribal knowledge that leaves with people. Two years later nobody knows why checkout calls inventory synchronously or why there are two order databases.
The fix in both worlds is the same: small, living, versioned documents — C4 diagrams that match production, ADRs that explain why, and design docs that capture the debate. In interviews, being able to sketch a clean C4 container diagram in two minutes and to talk about ADRs you wrote is a strong seniority signal.
Core concepts
The C4 model
C4 gives you a small set of abstractions — person, software system, container (a separately deployable/runnable unit: an app, a service, a database, a topic), component (a grouping of code inside a container) — and four zoom levels.
| Level | Shows | Audience | Keep current? |
|---|---|---|---|
| 1. System Context | Your system as a box, its users and the external systems it talks to | Everyone, including business and auditors | Yes |
| 2. Container | Deployable units inside your system, their technology and how they communicate | Engineers, SRE, security | Yes |
| 3. Component | Main building blocks inside one container | Engineers working on that container | Only for complex containers |
| 4. Code | Classes/types for one component | Rarely needed; generate from code if at all | No |
Supplementary views: System Landscape (many systems across the enterprise), Dynamic (a numbered sequence for one use case) and Deployment (containers mapped to infrastructure: clusters, AZs, regions, on-prem DCs).
Notation rules that make C4 diagrams readable:
- Every diagram has a title, a scope and a legend (or uses a well-known notation).
- Every element states its type and technology ("Container: Go service", "Container: PostgreSQL 16").
- Every arrow is unidirectional and labelled with intent and, at container level, protocol ("Publishes payment events [Kafka]").
- Avoid ambiguous acronyms; spell out on first use.
Level 1 — System Context
Level 2 — Container
Level 3 — Component (inside the Payment API)
Level 4 — Code (only if it helps)
Mermaid also has an experimental C4 diagram syntax (C4Context, C4Container); flowcharts like the above render more predictably today. For a single source model that generates every view consistently, Structurizr DSL (by Simon Brown) is the reference tool:
workspace "Payment Platform" {
model {
customer = person "Retail customer"
switch = softwareSystem "National payment switch" "External"
platform = softwareSystem "Payment Platform" {
api = container "Payment API" "Validates and accepts transfers" "Go"
db = container "Payment DB" "" "PostgreSQL"
bus = container "Event bus" "" "Kafka"
}
customer -> api "Makes transfers" "HTTPS"
api -> db "Reads/writes" "SQL"
api -> bus "Publishes events" "Kafka"
platform -> switch "Sends credit transfers" "ISO 20022"
}
views {
systemContext platform { include * autolayout lr }
container platform { include * autolayout lr }
}
}
Architecture Decision Records (ADRs)
Michael Nygard proposed ADRs in 2011: a short text file per architecturally significant decision, kept in the repository, numbered sequentially. The minimal template:
# ADR-NNN: <decision title, imperative>
Status: Proposed | Accepted | Deprecated | Superseded by ADR-MMM
Date: YYYY-MM-DD
Deciders: <names / roles>
## Context
Forces at play: requirements, constraints, NFRs with numbers, what is true today.
## Options considered
1. Option A — pros / cons
2. Option B — pros / cons
3. Do nothing — pros / cons
## Decision
What we will do, in active voice ("We will…").
## Consequences
Positive, negative and neutral results; risks accepted; follow-up work.
## Revisit when
Measurable triggers that would reopen this decision.
Variants: MADR (Markdown Any Decision Records) adds structured "decision drivers" and per-option pros/cons; Y-statements compress a decision into one sentence ("In the context of X, facing Y, we decided for Z and against W, to achieve Q, accepting D"). Tools such as adr-tools (Nat Pryce) create and link files from the command line.
ADR lifecycle:
Rules that keep ADRs valuable:
- One decision per ADR, one to two pages.
- Immutable once accepted. To change your mind, write a new ADR that supersedes the old one and link both ways. The history of reasoning is the value.
- Store with the code (
docs/adr/0007-use-kafka-for-payment-events.md) so they are reviewed in PRs and versioned with what they describe. Cross-cutting ADRs go in an architecture repository. - Write them for significant decisions: anything that affects structure, NFRs, dependencies, interfaces or construction techniques — and anything people will ask "why?" about later.
- Include rejected options. Future readers mostly want to know why not the obvious alternative.
Real-world style example
# ADR-007: Use Kafka for payment events
Status: Accepted
Date: 2026-03-12
Deciders: Head of Payments Engineering, Payments architect, SRE lead, InfoSec representative
## Context
- The payment platform must publish lifecycle events (TransferInitiated, TransferSettled,
TransferRejected) to at least five consumers: fraud monitoring, notifications,
reconciliation, the customer statement read model, and the data platform.
- Today events go through point-to-point IBM MQ queues configured on the ESB. Each new
consumer needs a new queue and an ESB change request (lead time ≈ 3–4 weeks).
- Reconciliation needs to re-read the last 7 days of events after an incident.
- Consumers need per-account ordering (a settlement must not be processed before its initiation).
- Load: ≈ 400 events/s average, ≈ 3,000 events/s at salary-day and Tết peaks; 3-year
growth estimate ≈ 5×.
- Regulatory: payment data must remain in-country; events contain account numbers (no card PANs).
- The platform team already runs Kafka for the data platform on the bank's private cloud
(3 brokers per DC, 2 DCs).
## Options considered
1. Keep IBM MQ via ESB — no new technology; but no replay, per-consumer queue changes,
ESB team bottleneck, fan-out requires duplicating messages.
2. RabbitMQ — simple, good routing; replay and long retention are not its strength;
no in-house operational experience.
3. Kafka (existing private-cloud cluster, managed by the platform team) — partitioned log,
replay by offset, consumer groups for fan-out, per-key ordering, schema registry already
in place; more complex client semantics, requires idempotent consumers.
4. Managed cloud streaming service — fast to start; rejected because payment data must stay
in the bank's in-country environment under current policy.
## Decision
We will publish payment events to Kafka on the existing private-cloud cluster:
- Topic per event family (payments.transfer.v1), partitioned by source account number,
initially 24 partitions.
- Producer: acks=all, idempotence enabled; replication factor 3, min.insync.replicas=2.
- Events published via the transactional outbox with Debezium CDC; no dual writes.
- Avro schemas in the schema registry with BACKWARD compatibility enforced in CI.
- Retention 7 days on the main topic; compacted topic for latest transfer state.
- Every consumer must be idempotent (dedup by event_id) — part of the definition of done.
## Consequences
+ New consumers subscribe without ESB change requests (lead time days, not weeks).
+ Reconciliation can replay up to 7 days by resetting offsets.
+ Per-account ordering preserved by key; no global ordering (consumers must not assume it).
- Teams must learn consumer-group semantics, offset management and DLQ handling.
- Kafka becomes tier-1 for payments: platform team on-call SLO must be raised to 99.95%.
- Cross-DC replication (MirrorMaker 2) adds lag for DR consumers; RPO for events ≈ seconds.
- IBM MQ remains for core-banking integration; this ADR does not replace the ESB.
## Revisit when
- Sustained peak above 15,000 events/s, or consumer lag above 60 s at peak for a week.
- Policy allows in-country managed cloud streaming.
- More than 20% of consumers need cross-partition ordering.
Notice what makes it useful: numbers, constraints (data residency), explicit rejection reasons, operational consequences, and revisit triggers. An auditor can follow it; a new engineer can understand why the topic is keyed by account.
arc42
arc42 (Gernot Starke and Peter Hruschka) is a free template with 12 sections. Use it as the table of contents for an HLD or a system's living architecture doc.
| # | Section | What goes in it | Bank emphasis |
|---|---|---|---|
| 1 | Introduction and goals | Purpose, top 3–5 quality goals, stakeholders | Regulatory drivers |
| 2 | Constraints | Technical, organizational, legal constraints | Data residency, approved tech list, vendor contracts |
| 3 | Context and scope | Business and technical context (C4 level 1) | External parties: switch, schemes, regulators |
| 4 | Solution strategy | Key decisions and approaches in a few bullets | |
| 5 | Building block view | Static decomposition (C4 levels 2–3) | |
| 6 | Runtime view | Important scenarios as sequence diagrams | Failure and reversal flows |
| 7 | Deployment view | Infrastructure, environments, DCs/regions | DR site, network zones |
| 8 | Cross-cutting concepts | Security, logging, error handling, i18n, persistence patterns | Audit trail, encryption, IAM |
| 9 | Architecture decisions | Links to ADRs | |
| 10 | Quality requirements | Quality tree and scenarios | RPO/RTO, availability |
| 11 | Risks and technical debt | Known risks with owners | Risk register mapping |
| 12 | Glossary | Ubiquitous language | Product and accounting terms |
RFC / design-doc process
For anything that is expensive to reverse or spans teams, write a design doc (often called an RFC) before implementation.
A typical design-doc template:
- Summary — three sentences: problem, proposal, impact.
- Context and goals / non-goals — non-goals prevent scope creep.
- Requirements and NFRs — measurable (see Quality Attributes).
- Proposed design — C4 container diagram, key sequences, data model, APIs.
- Alternatives considered — and why not.
- Cross-cutting concerns — security and privacy, observability, failure modes, migration and rollback, cost.
- Rollout plan — phases, feature flags, success metrics.
- Open questions.
Process norms that work:
- Time-box review (e.g. one week) and name the decision-maker up front.
- Comments are asynchronous first; meet only to resolve the remaining disagreements.
- Reviewers should include at least one person from security and one from operations for anything customer-facing or touching money.
- Outcome becomes one or more ADRs; the design doc stays as the record of the debate.
- At a bank, the approved design doc is the HLD for the architecture review board — avoid writing two documents.
Diagrams as code
| Tool | Strengths | Weaknesses |
|---|---|---|
| Mermaid | Renders in GitHub, GitLab, Docusaurus, Confluence (plugins); easy syntax | Layout control limited; large diagrams get messy |
| PlantUML (+ C4-PlantUML) | Mature, many diagram types, official-looking C4 shapes | Java-based renderer; syntax heavier |
| Structurizr DSL | One model, many consistent views; C4-native | Separate tool/renderer; learning curve |
| D2 | Modern syntax, good auto-layout | Smaller ecosystem |
| Draw.io / Excalidraw files in repo | Freeform, great for whiteboarding | Diffs are unreadable; drift easily |
Practices:
- Diagrams live in the repo next to the code they describe and are reviewed in the same PR as the change.
- Render in CI and publish to the docs site (as this handbook does) so there is one canonical view.
- Prefer a model-based tool (Structurizr) when many diagrams share elements, so renaming a container updates every view.
- Keep each diagram to roughly 15–20 elements; split by scope if it grows.
Trade-offs
| Artifact | Strengths | Weaknesses | Choose when |
|---|---|---|---|
| C4 context + container only | Cheap to maintain, high value | Lacks internal detail | Default for every system |
| Full C4 incl. components | Helps onboarding to complex containers | Drifts quickly | Complex, long-lived containers (ledger, pricing engine) |
| ADRs | Captures why; cheap; immutable history | Needs discipline; can become noise if overused | Every significant decision |
| arc42 full document | Complete, auditor-friendly | Effort; stale sections | Regulated systems, vendor handover, ARB submissions |
| Design doc / RFC | Surfaces risks early; async review scales | Can stall delivery if not time-boxed | Cross-team or one-way-door changes |
| Wiki pages | Easy to edit | Drift from code, no review | Team notes, onboarding guides — not decisions |
In practice
A minimal, sustainable documentation set per system:
payment-platform/
docs/
architecture/
README.md # arc42-lite: goals, constraints, context, strategy, risks
c4-context.mmd # Mermaid, rendered in CI
c4-container.mmd
runtime-transfer.mmd # sequence for the main flow + failure flows
deployment.mmd # AZs/DCs, network zones
adr/
0001-record-architecture-decisions.md
0007-use-kafka-for-payment-events.md
0012-ledger-domain-has-no-io.md
runbooks/
switch-timeout.md
- ADR-0001 is "We will record architecture decisions" — it sets the convention.
- Add a PR template checkbox: "Does this change need an ADR or a diagram update?"
- Review the ADR log quarterly; superseded and deprecated ADRs tell you where your architecture is evolving.
- For bank audits, link ADRs and design docs from change records; the evidence trail then comes for free.
Common pitfalls
- Write-once HLDs. Approved, archived, never updated. Symptom: production looks nothing like the document the auditor is reading.
- Boxes and lines without meaning. No legend, unlabelled arrows, mixed abstraction levels (a Kafka topic next to "Customer domain"). Symptom: every reader interprets it differently.
- Editing accepted ADRs. Symptom: nobody can tell what was decided when, or why it changed.
- ADRs for trivia. "Use testify for assertions." Symptom: the log becomes noise and people stop reading it.
- Design docs as approval theatre. Written after the code. Symptom: reviews are rubber stamps; risks are found in production.
- Diagrams in personal tools. Symptom: the only up-to-date diagram is on a laptop belonging to someone who just resigned.
Interview angle
- When you start a design question, draw a C4 context diagram first (users, your system, external systems), then the container view. Interviewers find this structured and easy to follow.
- Expect: "How do you document architecture in your team?" A strong answer: C4 context + container as code, ADRs in the repo, design docs for one-way doors, quarterly review — with an example ADR you wrote.
- Expect: "Tell me about a decision you'd make differently now." Use an ADR-shaped story: context, options, decision, consequences, what changed.
- Bank-specific: be ready to explain how your documentation supports audits and the architecture review board without duplicating effort.
- Red flags: "the code is the documentation"; diagrams without a legend or technologies; no notion of recording why.
Self-check
1. What is a "container" in C4, and why is a Kafka topic or a database a container?
A container is a separately runnable or deployable unit that executes code or stores data: a service, a web app, a mobile app, a database, a message topic or bucket. Databases and topics are containers because they are distinct runtime units with their own technology, deployment and failure characteristics — not to be confused with Docker containers.
2. Which C4 levels would you maintain for a bank payment platform, and why not all four?
System context (for business, auditors and security) and container (for engineers and SRE), plus a deployment view for DR and network zones, and dynamic views for the main and failure flows. Component diagrams only for complex containers like the orchestrator or ledger. Code-level diagrams drift instantly and are better generated from code or omitted.
3. Why are ADRs immutable once accepted, and how do you change a decision?
The value of ADRs is the history of reasoning: what was known and decided at the time. Editing destroys that history. To change a decision, write a new ADR with the new context and decision, mark the old one "Superseded by ADR-N" and link both ways.
4. What makes the Kafka ADR example useful to a future reader? List four elements.
- Quantified context (event rates, growth, replay window).
- Explicit constraints (data residency, existing platform skills).
- Rejected options with reasons (MQ, RabbitMQ, managed cloud service).
- Operational consequences (tier-1 on-call, idempotent consumers, DR lag) and measurable revisit triggers.
5. Scenario: your bank's ARB demands a 60-page HLD template while your team uses design docs and ADRs. How do you avoid writing everything twice?
Map the ARB template to arc42-style sections and generate the HLD from existing artifacts: context and container diagrams from the repo, quality requirements from the NFR file, decisions as links to ADRs, runtime and deployment views from diagrams-as-code. Agree with the ARB that the design doc plus linked ADRs satisfies the template, and fill only the gaps (e.g. compliance mapping) once.
6. Name three things that should always be in a design doc beyond the proposed solution.
Goals and non-goals; alternatives considered with reasons for rejection; cross-cutting concerns (security, observability, failure modes, migration and rollback, cost); rollout plan with success metrics; open questions.
Exercise
For a system you know (or the QR & Instant Payment System):
- Draw C4 context and container diagrams in Mermaid following the notation rules (types, technologies, labelled arrows).
- Draw a dynamic (sequence) view for the happy path and one failure path (timeout from the switch).
- Write three ADRs: one for messaging, one for the database, one for how you handle idempotency. Include rejected options and revisit triggers.
- Create an arc42-lite README with sections 1, 2, 3, 4, 10 and 11 filled in.
Done when: someone unfamiliar with the system can answer "what are the external dependencies, what happens if the switch times out, and why did you pick this database?" using only your docs.
Further reading
- Simon Brown, The C4 model for visualising software architecture (c4model.com) and Software Architecture for Developers (Leanpub).
- Michael Nygard, "Documenting Architecture Decisions" (Cognitect blog, 2011).
- arc42 template and documentation (arc42.org) — Gernot Starke, Peter Hruschka.
- Documenting Software Architectures: Views and Beyond — Clements et al. (SEI series, 2nd ed. 2010).
- Malte Ubl, "Design Docs at Google" (industrialempathy.com, 2020).
- MADR — Markdown Any Decision Records (adr.github.io).
Related
- The Role of a Solution/System Architect — where documentation fits in the architect's loop.
- Quality Attributes & Trade-off Analysis — the NFRs your documents must capture.
- Event-Driven Architecture, CQRS & Event Sourcing — background for the Kafka ADR.
- Message Queues & Event Streaming — Kafka semantics referenced in the ADR.
- Code Review & Engineering Standards — reviewing docs and ADRs in PRs.
- System Design Interview Framework — drawing C4-style diagrams under time pressure.
Do the self-check first. Marking it complete schedules spaced reviews (1, 3, 7, 14, 30… days).