SelfscribeDownloadOpen the app

On-call runbook

A system map that colours itself from a status table, with the steps to take when something is red.

Document · Advanced · uses diagram, table, code

Edit it in the playgroundRead the file

What it shows

Draw a system map whose boxes take their colour from a status table.

What you learn

A flow diagram with groups and shapes, a diagram coloured from a data block, boxes for "do this first" and "never do this", a word that becomes a badge, a decision flow, swimlanes for who does what.

Try this

  • In the status table, change Payment provider from at risk to ok, and its box on the map turns green.
  • Add node cache "Basket cache" and api -> cache "reads" to the map, and it lays itself out again.
examples/on-call-runbook.self · 245 lines
~~~ selfscribe
# Lesson: Draw a system map whose boxes take their colour from a status table.
# You learn: a flow diagram with groups and shapes, a diagram coloured from a data block, boxes for "do this first" and "never do this", a word that becomes a badge, a decision flow, swimlanes for who does what.
# Try this: in the status table, change Payment provider from at risk to ok, and its box on the map turns green.
# Try this: add `node cache "Basket cache"` and `api -> cache "reads"` to the map, and it lays itself out again.
# summary: A system map that colours itself from a status table, with the steps to take when something is red.
# category: plans
# tags: document, advanced, work
# uses: diagram, table, code
use markdown
use data
set title On-call runbook
set style sans
set width wide
set lang en-GB

# ---- The palette: each colour named once, with its shade for dark pages ----------------
# The paler shades are their own entries, so they follow the dark page by themselves.
palette
  alert   #c92a2a  dark #ff8787
  calm    #1d4f91  dark #8ab8f5
  alertbg color-mix(in srgb, var(--alert) 8%, transparent)
  calmbg  color-mix(in srgb, var(--calm) 8%, transparent)

# ---- "oncall a · b · c" under the title: who this page is for, as chips ---------------
line   oncall _  -> div.rb-for  split "·" span.rb-chip  { display: flex; flex-wrap: wrap; gap: 0.45em; margin: -0.5em 0 1.4em }  as rb-for
class rb-chip  { font: 600 0.8em/1 var(--doc-font-ui); padding: 0.55em 0.9em; border-radius: 999px; background: var(--calmbg); color: var(--calm) }

# ---- "::: first" ... ":::" and "::: never" ... ":::": a blue box and a red box ---------
# Both share the class box for their shape, and each adds only its colour.
class box { margin: 1em 0; padding: 0.6em 1.1em; border-radius: 8px; border-left: 5px solid }
block  ::: first ... :::  -> aside.box.first  { border-color: var(--calm); background: var(--calmbg) }  as first
block  ::: never ... :::  -> aside.box.never  { border-color: var(--alert); background: var(--alertbg) }  as never

# ---- PAGE anywhere in the text: a red badge, so who to page stands out ---------------
word   PAGE  -> span.page  { font: 700 0.75em/1 var(--doc-font-ui); letter-spacing: 0.06em; color: var(--alert); border: 1px solid; border-radius: 4px; padding: 0.15em 0.4em }

# ---- "```flow" ... "```": a diagram written one line at a time ------------------------
# "node id "Label" :shape" draws a box, "a -> b "label"" an arrow, "group" and "lane" boxes around others.
# "set data=components" colours each node from the row of the components table with the same name.
block  ``` flow ... ```  -> flow  verbatim

# ---- "```timezones" ... "```": one moment, read in each place the rota covers ------------
# The line with a time is the moment; the next names the places; the last row is the reader's own.
block  ``` timezones ... ```  -> timezones  verbatim
~~~
# Checkout on-call runbook

oncall The Pay button of the web shop and the app · Pager: "checkout primary" · Incident channel: #shop-incidents

```flow
set direction=LR
set data=components
node customer "Customer" :person
node store "Storefront"
group cluster "Checkout cluster, 12 instances" {
  node api "Checkout API" :service
  node client "Payments client"
  node relay "Outbox relay"
}
node pricing "Pricing" :service
node stock "Inventory" :service
node db "Orders database" :database
node queue "Order events" :data
node provider "Payment provider" :cloud
customer -> store
store -> api "HTTPS"
api -> pricing
api -> stock "reserve"
api -> client
client -> provider "charge" dash=dashed
api -> db "order + outbox"
relay -> db "reads outbox"
relay -> queue "sends"
```

::: first
**In the first five minutes**

1. Acknowledge the page, so it does not go to the next person.
2. Open the checkout dashboard and note the error rate and the time it started.
3. Post one line in #shop-incidents: what you see, and that you are looking.
4. Set the parts you suspect to `at risk` in the status table, so the map shows them.
5. Follow [Orders are failing](#orders-are-failing) below, from the top.
:::

::: never
**Two things that make it worse**

Never retry payments by hand, and never restart every checkout instance at once. A retried payment can charge a customer twice, and a full restart drops every basket being paid for.
:::

## What each part should look like

Each box on the map takes its colour from this table: green is ok, red is at risk or failed. Whoever is on call keeps it up to date during an incident, so the next person sees the same picture.

```data components as table
name, status:choice(ok|at risk|failed), owner, look at
Storefront, ok, Web team, the shop's front page loads
Checkout API, ok, Checkout team, error rate under 0.5%
Payments client, at risk, Checkout team, open connections under 160 per instance
Outbox relay, ok, Checkout team, outbox rows older than 1 min: none
Pricing, ok, Catalogue team, answers in under 50 ms
Inventory, ok, Warehouse team, answers in under 80 ms
Orders database, ok, Database on call, replication lag under 1 s
Order events, ok, Fulfilment team, queue depth under 500
Payment provider, at risk, Payments lead, the provider's status page
```

How the parts work is in [How our checkout service works](big-ideas.self).

## Orders are failing

Start here when the error-rate alert fires, or support says customers cannot pay. Take the first question whose answer you know, and go down.

```flow
node alert "Checkout errors above 2%" :start
node release "A release in the last hour?" :decision
node rollback "Roll back that release"
node falling "Errors falling within 10 min?" :decision
node provider "Provider's status page red?" :decision
node banner "Turn on the 'try again shortly' banner"
node pool "Connections at the limit?" :decision
node restart "Restart instances one at a time"
node db "Orders database healthy?" :decision
node failover "Page database on call"
node incident "Declare an incident" color=red
node watch "Watch for 30 min, then write it up" :end
alert -> release
release -> rollback "yes"
release -> provider "no"
rollback -> falling
falling -> watch "yes"
falling -> incident "no"
provider -> banner "yes"
provider -> pool "no"
banner -> incident
pool -> restart "yes"
pool -> db "no"
restart -> falling
db -> incident "yes"
db -> failover "no"
failover -> incident
```

A rollback is the first answer whenever a release is recent, even before you know the cause. The [incident review of 18 November](incident-review.self) is the reason: the rollback ended it in twelve minutes, while the cause took two hours to find.

## Who does what in an incident?

Once you declare an incident, the work splits four ways. You stay on the fix; the incident lead talks to everyone else.

```flow
set direction=LR
lane oncall "On call" {
  node declare "Declare in #shop-incidents" :start
  node fix "Work on the fix"
  node done "Errors below 0.5%" :end
}
lane lead "Incident lead" {
  node take "Take the lead"
  node update "Update every 15 min"
  node close "Close and book the review" :end
}
lane support "Support" {
  node reply "Saved reply to customers"
}
lane payments "Payments lead" {
  node provider "Call the provider"
}
link declare -> take
link declare -> fix
link take -> update
link take -> reply "tells"
link take -> provider "if payments"
link provider -> fix "what they see"
link fix -> done
link done -> close
```

## Commands

Roll back the checkout service to the release before this one. It takes about twelve minutes for all instances.

```sh
deploy rollback checkout --to previous
deploy status checkout --watch
```

Restart one instance at a time, waiting for each to report healthy before the next.

```sh
deploy restart checkout --one-at-a-time --wait-healthy
```

Turn the "try again shortly" banner on and off. Customers can still browse, and baskets are kept.

```sh
flags set checkout.pay-banner on
flags set checkout.pay-banner off
```

## Who to call

| When | Who | How |
|---|---|---|
| You need a second pair of hands | The secondary on call | the pager rota, "checkout secondary" |
| An incident is declared | Lena Fischer, incident lead | PAGE incident lead |
| The payment provider is involved | Sara Lindgren, payments lead | PAGE payments lead |
| The orders database is unhealthy | Database on call | PAGE database |
| More than an hour, or money taken twice | Head of engineering | phone, from the pager rota |

## When the pager changes hands

The rota follows the sun. Berlin hands the pager to Toronto at the end of its day, and Toronto hands it to Singapore at the end of its own. Each handover is a ten-minute call: what is open, what is at risk in the status table, and who has been paged.

```timezones
# Berlin hands over to Toronto
17:00 Berlin
Toronto, Singapore
hours 8-18
```

Look at the Toronto row before you book the call. For three weeks in March and one in autumn, the clocks have changed on one side of the Atlantic and not yet on the other, and the call moves by an hour.

## How it's made

- The map is a fenced block named `flow`: `node api "Checkout API" :service` draws a box,
  `api -> db "order + outbox"` an arrow, and `group` draws a box around others.
- Its line `set data=components` reads the status table. Each box takes the colour of the row
  with its name, so changing a status in the table recolours the map.
- The decision flow uses `:decision` shapes, and the swimlanes are `lane` boxes.
- The blue and red boxes are `::: first` and `::: never`, and every `PAGE` in the text becomes a
  badge.
- The handover is a `timezones` block. `17:00 Berlin` is the moment, today, and the next line
  names the places to read it in. Each row is that place's own clock, and the last row is yours.

## Try it yourself

1. In the status table, change `Payment provider, at risk` to `Payment provider, ok`. The provider's box on the map turns green.
2. Set `Orders database` to `failed`. Its box turns red.
3. In the decision flow, add `node cache "Clear the basket cache"` and `restart -> cache`. A new step appears after the restart, and the flow lays itself out again.
4. In the swimlanes, add `node page "Page the secondary"` inside the On call lane and `link fix -> page`. The lane grows a step.
5. In the handover, change `17:00 Berlin` to `Friday 20 March 2026, 17:00 Berlin`. Toronto reads 12:00, not 11:00: North America moves its clocks three weeks before Europe.

Next: *Incident review* is the incident this runbook learned from; *Diagrams that move* makes a flow like these come alive.