How a system works
Explain a system to a newcomer with small pictures drawn from lists.
What it shows
Explain a system to a newcomer with small pictures written as lists.
What you learn
A name marked the same way in every sentence, a stack of layers with a path through it, boxes inside boxes from indentation, a scale of speeds, a time budget against a limit, a funnel, a trail of one order, a weighed choice, a key taken apart, who owns what.
Try this
- In the time budget, change "Payment provider: 420 ms" to 720 ms, and the bar runs past the 800 ms limit.
- Put > before another layer of the stack, and that layer lights up as well.
How checkout works at Fernhill
The map for your first week on the checkout team.
Checkout team11,300 orders on a weekday800 ms budget for the Pay buttonChecked against the code on 18 November 2026
This page follows one customer paying for one basket through every part we run. The parts always go by the same names, like Checkout API, in the text and in the pictures.
Each layer only talks to the one under it. The Storefront never calls Pricing or Inventory directly at checkout. It asks the Checkout API, which asks them, so the price a customer pays is the price we checked.
When something here no longer matches the code, fix the page in the same pull request.
What runs inside what?
The Payments client runs inside each checkout instance, not as a service of its own. A problem in it is a problem in every instance at once.
How fast is each part?
Seen from the Checkout API, at the 95th percentile on a normal afternoon.
Everything we run is fast next to the Payment provider. When checkout is slow, look there first.
Where does the time of one checkout go?
The Pay button has a budget of 800 ms on our side, from the request arriving to the answer leaving.
There is room for one retry of a quick call, but not of a payment. That is why the Payments client never retries on its own.
Where do customers drop out?
A typical weekday, from the payments dashboard.
What happens to one order?
From the Pay button to the warehouse, with who does each step and how long it takes.
The order and its event are written together, so an order can never exist without the warehouse hearing of it.
Why an outbox, and not a direct call?
We weighed three ways to tell fulfilment about a new order.
How do I read a payment key?
Every payment carries an idempotency key, so a payment sent twice is taken once. You will see it in logs and in the provider's dashboard.
If two payments share everything up to the attempt, the customer pressed Pay twice. That is normal.
Who owns what?
Anything that touches the Payments client or the provider's settings needs the payments lead's sign-off, even a library upgrade. The incident review shows why, and the on-call runbook is where to go when checkout breaks.
How it's made
Each picture is a fenced block of plain lines, such as layers or funnel, and one rule per block in the rules block names the picture it draws. Without the plugins, every block still reads as a list.
- A name in curly brackets, such as
{Checkout API}, is marked in blue by theinline {_}rule, so you can follow one part from the text to the pictures. >before a line lights it. Each section lights the part it is about.- The
path Pay:line under the stack draws the journey of one request beside the layers.
Try it yourself
- In the time budget, change
Payment provider: 420 msto720 ms. The bar runs past the 800 ms limit, and the 30 ms over is struck through in red. - In the stack, put
>beforeStores. The stores layer lights up beside the Checkout API. - In the boxes, indent
Order eventstwo more spaces. Its box moves inside the Orders database. - In the funnel, change
Paid: 11,300toPaid: 10,100. The last bar narrows, and the share that went on from Pressed Pay drops. - In the choice, move the
*fromOutbox tabletoSend to the queue. The chosen column moves with it.
Next: Picture an idea shows every one of these blocks and more; On-call runbook uses the same parts when things break.
~~~ selfscribe
# Lesson: Explain a system to a newcomer with small pictures written as lists.
# You learn: a name marked the same way in every sentence, a stack of layers with a path through it, boxes inside boxes from indentation, a scale of speeds, a time budget against a limit, a funnel, a trail of one order, a weighed choice, a key taken apart, who owns what.
# Try this: in the time budget, change "Payment provider: 420 ms" to 720 ms, and the bar runs past the 800 ms limit.
# Try this: put > before another layer of the stack, and that layer lights up as well.
# summary: Explain a system to a newcomer with small pictures drawn from lists.
# category: diagrams
# tags: document, advanced, work, ideas
# uses: diagram
use markdown
set title How a system works
set style sans wide
set heading-font IBM Plex Sans
# ---- Colours, each with its shade for dark pages ----------------------------------------
palette
part #1d4f91 dark #8ab8f5
partbg color-mix(in srgb, var(--part) 10%, transparent)
# ---- "> a line": the line under the title, in the page's own voice -----------------------
line > _ -> p.lede { margin: -0.3em 0 0.9em; font-size: 1.15em; line-height: 1.5; opacity: 0.82 } as lede
# ---- "facts a | b | c": the team at a glance, as tags in a row ---------------------------
line facts _ -> p.facts split "|" span.fact { display: flex; flex-wrap: wrap; gap: 0.4em; margin: 0 0 1.4em } as facts
class fact { padding: 0.2em 0.75em; border-radius: 999px; background: var(--partbg); color: var(--part); font: 600 0.82em/1.6 var(--doc-font-ui) }
# ---- "{Orders database}" in a sentence: a part of the system, marked in blue ----------
# Every block below names the same parts, so the blue names tie the text to the pictures.
inline {_} -> span.part
class part { font-family: var(--doc-font-ui); font-size: 0.9em; font-weight: 600; color: var(--part); background: var(--partbg); padding: 0.05em 0.4em; border-radius: 4px; white-space: nowrap }
# ---- Fenced blocks, each drawn as one kind of picture ---------------------------------
# In most of them, a first line that starts with "#" is a caption, ">" before a line lights it,
# " | " adds a note, and a last line that starts with "=>" is the conclusion.
# "Top | detail | note" per line: a stack of layers, the first line on top. "path" draws a journey.
block ``` layers ... ``` -> layers verbatim
# Indent a line under another, and its box is drawn inside the other's.
block ``` nest ... ``` -> nest verbatim
# "Name: amount unit" per line: each on one scale, so 0.2 ms and 3 s sit on the same ruler.
block ``` scale ... ``` -> scale verbatim
# "limit: 800 ms", then the parts: one bar, coloured where it runs over.
block ``` budget ... ``` -> budget verbatim
# "Step: count" per line: each step narrower than the one before, with the share lost.
block ``` funnel ... ``` -> funnel verbatim
# "Step | who | how long" per line; an indented "yes:" or "no:" line is a branch.
block ``` trail ... ``` -> trail verbatim
# A header row of options, then "Question: + good | - bad | ~ so-so"; a * marks the one chosen.
block ``` versus ... ``` -> versus verbatim
# The thing on its own line, then "piece: name | what it means" for each part of it.
block ``` anatomy ... ``` -> anatomy verbatim
# A header row of people, then "Task: what each does" per line.
block ``` who ... ``` -> who verbatim
~~~
# How checkout works at Fernhill
> The map for your first week on the checkout team.
```layers
# One press of the Pay button, from the customer down
Storefront | web shop, phone app | what the customer sees
Edge | CDN, load balancer | TLS ends here
> Checkout API | basket, order, payment steps | this team
Domain services | Pricing, Inventory, Payments client | one call each per order
Stores | Orders database, Outbox, Order events | what survives a restart
path Pay: Storefront > Edge > Checkout API > Domain services > Stores
```
facts Checkout team | 11,300 orders on a weekday | 800 ms budget for the Pay button | Checked against the code on 18 November 2026
This page follows one customer paying for one basket through every part we run. The parts always go by the same names, like {Checkout API}, in the text and in the pictures.
Each layer only talks to the one under it. The {Storefront} never calls {Pricing} or {Inventory} directly at checkout. It asks the {Checkout API}, which asks them, so the price a customer pays is the price we checked.
When something here no longer matches the code, fix the page in the same pull request.
## What runs inside what?
```nest
Region eu-west
Checkout cluster | 12 instances in normal hours
Checkout API
Payments client | a library in the same process
Sidecar | logs, metrics and traces
Pricing | owned by the catalogue team
Inventory | owned by the warehouse team
Orders database | Postgres, one primary, two replicas
orders
outbox | events waiting to be sent
Order events | a queue that fulfilment reads
Payment provider | outside our network
```
The {Payments client} runs inside each checkout instance, not as a service of its own. A problem in it is a problem in every instance at once.
## How fast is each part?
Seen from the {Checkout API}, at the 95th percentile on a normal afternoon.
```scale
# One call, from our side
Read from the in-process cache: 0.2 ms
Orders database, one row: 3 ms
Pricing: 25 ms
Inventory: 40 ms
> Payment provider: 420 ms
Customer's patience at the Pay button: 3 s
```
Everything we run is fast next to the {Payment provider}. When checkout is slow, look there first.
## Where does the time of one checkout go?
The Pay button has a budget of 800 ms on our side, from the request arriving to the answer leaving.
```budget
# Pressing Pay
limit: 800 ms
Check the basket: 20 ms
Pricing: 25 ms
Inventory, reserve the items: 40 ms
> Payment provider: 420 ms
Write the order and its outbox row: 15 ms
Answer the Storefront: 10 ms
```
There is room for one retry of a quick call, but not of a payment. That is why the {Payments client} never retries on its own.
## Where do customers drop out?
A typical weekday, from the payments dashboard.
```funnel
# From basket to paid order
Opened the basket: 41,000
Started checkout: 18,500
Entered a delivery address: 14,200
> Pressed Pay: 11,900
Paid: 11,300
=> Most of the loss is before the Pay button, so our errors are rare but costly: every failed payment is a customer who had already decided.
```
## What happens to one order?
From the Pay button to the warehouse, with who does each step and how long it takes.
```trail
Pay pressed | Storefront
Basket still valid? | Checkout API | 20 ms
no: Show the new price or stock, and ask again
yes: Reserve the items | Inventory | 40 ms
Take the payment | Payment provider | 420 ms
no: Release the items, and say why | Checkout API
yes: Write the order and an outbox row, in one transaction | Orders database
Order confirmed to the customer | Checkout API
Outbox row sent as an event | Outbox relay | ≤2 s
Picked and packed | Fulfilment | same day
```
The order and its event are written together, so an order can never exist without the warehouse hearing of it.
## Why an outbox, and not a direct call?
We weighed three ways to tell fulfilment about a new order.
```versus
| Call fulfilment directly | Send to the queue | *Outbox table
Fulfilment down: - checkout fails | + checkout carries on | + checkout carries on
Order without an event: + never | - possible, if we crash between the two | + never: one transaction
Speed of the Pay button: - adds 60 ms | ~ adds 5 ms | + adds 2 ms
Moving parts: + none new | ~ the queue | - a relay to run
=> Outbox table: losing an order costs more than running one small relay.
```
## How do I read a payment key?
Every payment carries an idempotency key, so a payment sent twice is taken once. You will see it in logs and in the provider's dashboard.
```anatomy
# The key on one payment
co-eu-20261118-7f3a9c-p1
co: checkout | which service made it
eu: region
20261118: the day | when the basket was opened
7f3a9c: basket | the start of the basket's id
p1: attempt | goes up when the customer presses Pay again
```
If two payments share everything up to the attempt, the customer pressed Pay twice. That is normal.
## Who owns what?
```who
# Changes to checkout
| Checkout team | Payments lead | Catalogue team | Support
Checkout API: does, signs off | asked | told | told
Payments client: does | signs off | - | told
Pricing rules: told | - | does, signs off | told
> Payment provider settings: asked | does, signs off | - | told
Refunds by hand: told | signs off | - | does
```
Anything that touches the {Payments client} or the provider's settings needs the payments lead's sign-off, even a library upgrade. The [incident review](incident-review.self) shows why, and the [on-call runbook](on-call-runbook.self) is where to go when checkout breaks.
## How it's made
Each picture is a fenced block of plain lines, such as `layers` or `funnel`, and one rule per block in the rules block names the picture it draws. Without the plugins, every block still reads as a list.
- A name in curly brackets, such as `{Checkout API}`, is marked in blue by the `inline {_}` rule, so you can follow one part from the text to the pictures.
- `>` before a line lights it. Each section lights the part it is about.
- The `path Pay:` line under the stack draws the journey of one request beside the layers.
## Try it yourself
1. In the time budget, change `Payment provider: 420 ms` to `720 ms`. The bar runs past the 800 ms limit, and the 30 ms over is struck through in red.
2. In the stack, put `>` before `Stores`. The stores layer lights up beside the Checkout API.
3. In the boxes, indent `Order events` two more spaces. Its box moves inside the Orders database.
4. In the funnel, change `Paid: 11,300` to `Paid: 10,100`. The last bar narrows, and the share that went on from Pressed Pay drops.
5. In the choice, move the `*` from `Outbox table` to `Send to the queue`. The chosen column moves with it.
**Next:** *Picture an idea* shows every one of these blocks and more; *On-call runbook* uses the same parts when things break.