System Design · Architecture

Diagramming & C4

Diagrams at four zoom levels, each with one audience — and how to keep them true a year later.

— min read System Design

One Diagram, One Question

Most architecture diagrams fail because they answer several questions at once: boxes at different zoom levels, arrows meaning three different things, and no legend. A diagram should answer one question for one audience.

The two habits that fix most of it: label every arrow with what actually flows and in which direction, and state the zoom level in the title. An unlabelled arrow between two boxes tells a reader nothing — is that an HTTP call, a shared database, a nightly export, or an aspiration?

The C4 Model

C4 gives four levels, each a zoom into the previous one, so a reader can choose the altitude they need.

LevelShowsAudience
1 — ContextYour system, its users and the systems it talks toAnyone, including non-technical
2 — ContainerDeployable units: apps, services, databases, queuesEngineers and operations
3 — ComponentThe major parts inside one containerEngineers working on it
4 — CodeClasses and relationshipsRarely drawn — generate it if needed
Levels 1 and 2 carry nearly all the value. A context diagram and a container diagram, both accurate, are worth more than a folder of detailed component drawings that stopped matching the code a year ago.

A container in C4 is a deployable or runnable thing — a service, a single-page app, a database, a message broker — not a Docker container specifically. It is the level at which most architectural conversations actually happen.

Sequence & Flow Diagrams

Static diagrams show structure; sequence diagrams show what happens over time, which is what most incident and design discussions actually need.

Draw one whenBecause
A flow crosses several servicesThe ordering and failure points are the design
Explaining an authentication handshakeSteps and their order are the entire content
Documenting an incidentThe timeline is the finding
Designing a retry or compensation pathThe unhappy path is where the complexity lives
sequenceDiagram
    Client->>API: POST /orders
    API->>Payments: authorise(card, amount)
    Payments-->>API: authorised
    API->>DB: save order (pending)
    API-->>Client: 202 Accepted
    Note over API,DB: capture happens asynchronously
Text-based diagrams — Mermaid, PlantUML, Structurizr — live in the repository, diff in a pull request and are edited by whoever changes the code. A PNG exported from a drawing tool is stale the first time someone lacks the source file.

Keeping Them True

A wrong diagram is worse than no diagram. It is trusted, it is used to plan work, and the correction only arrives when something breaks in a place the drawing said did not exist.
PracticeEffect
Diagrams as code, in the repositoryThey change in the same pull request as the code
Few diagrams, kept currentBeats many that are all slightly wrong
Date and owner on eachA reader can judge how much to trust it
Reviewed when boundaries changeThe moment the container diagram becomes wrong
Delete rather than let rotAn absent diagram is honest; a stale one lies

The pragmatic target for most teams is two diagrams that are always right — a context and a container view — plus sequence diagrams drawn for specific flows when they are being designed or debugged.

Interview Questions

What are the four C4 levels?

Context (system, users, external systems), container (deployable units), component (parts inside a container) and code. Levels 1 and 2 carry nearly all the value.

What is a container in C4?

A separately deployable or runnable thing — a service, a single-page app, a database, a broker. Not a Docker container specifically.

Why label every arrow?

An unlabelled arrow could be an HTTP call, a shared database, a nightly export or an intention. The label and its direction are what make the diagram a statement rather than a sketch.

Why prefer diagrams as code?

They live in the repository, diff in review, and get updated by whoever changes the system. An exported image goes stale the moment the source file is lost.

When is a sequence diagram the right tool?

When ordering and failure points are the design — cross-service flows, authentication handshakes, retry and compensation paths, and incident timelines.

What do you do with a diagram nobody maintains?

Delete it. An absent diagram is honest about the gap; a stale one is trusted and used to plan work, which is how it causes damage.

Quick Quiz

1. C4 level 2 shows…
2. The most valuable C4 levels are usually…
3. An unlabelled arrow between two boxes…
4. Diagrams as code are preferred because they…
5. A stale diagram is…