Pidoku

Archive

This learning material is in the archive. It is not currently maintained and has not been updated with the latest information, so tool versions, prices and dates may be out of date.

A Service from Zero to SRE-Supported

Module 11 Lesson 11.c 1h 15m Difficulty 3/5

Prerequisites Modules 1–10

The idea in one minute#

This lesson applies the whole material to one service, in order, over twelve weeks. The service is orders-api at a mid-sized online shop: it takes orders from the web and mobile apps, writes them to PostgreSQL, calls payments and inventory, and publishes events for fulfilment. At the start it has no SLOs, pages on CPU, deploys by hand on Thursdays, and has had four incidents in two months.

At the end it has SLOs and a policy, burn-rate alerts with runbooks, a humane rotation, postmortems, deadlines and retry budgets, load shedding, three-zone redundancy, a canary pipeline, tested restores, a DR plan, monthly chaos experiments, and it passes its production readiness review. Each step names the lesson it comes from, so this is also a map of the material.

An analogy#

Renovating a house while living in it. You do not knock everything down; you fix the wiring that could start a fire first, then the roof, then the plumbing — one room at a time, keeping the house habitable throughout.

A picture#

flowchart LR
  W1["Weeks 1–2<br/><b>Measure</b><br/><small>CUJs, SLIs, SLOs, policy</small>"] --> W3["Weeks 3–4<br/><b>Alert and respond</b><br/><small>burn rate, runbooks, rotation</small>"]
  W3 --> W5["Weeks 5–6<br/><b>Stop the bleeding</b><br/><small>timeouts, retries, shedding</small>"]
  W5 --> W7["Weeks 7–8<br/><b>Change safely</b><br/><small>canary, flags, k8s settings</small>"]
  W7 --> W9["Weeks 9–10<br/><b>Survive loss</b><br/><small>zones, capacity, backups, DR</small>"]
  W9 --> W11["Weeks 11–12<br/><b>Prove it</b><br/><small>chaos, game day, PRR</small>"]
  class W1 memory
  class W3 warn
  class W5 io
  class W7 compute
  class W9 queue
  class W11 neutral

How it really works#

The starting point#

FactValue
Traffic~180 orders/s at peak, 2.4 M requests/day across endpoints
Architecture4 pods (often 3 in one zone), PostgreSQL primary + 1 async replica, Redis cache
Dependenciespayments (external), inventory (internal), Kafka for events
DeploysWeekly, manual kubectl apply, no canary
Alerts23 rules; ~45 pages a month, 70% not actionable
On-call4 developers, weekly, no secondary
Last 2 months4 incidents: bad deploy (2×), payments timeouts cascading, disk full on the DB

Weeks 1–2: measure (Module 2)#

  1. Critical user journeys (2.a): place an order; view order status. Admin endpoints are out of scope.
  2. SLIs at the load balancer (2.a): place-order availability (non-5xx and not 429, excluding 4xx client errors) and latency (< 1 s); order-status availability.
  3. History (2.b): 12 weeks of LB logs: availability 99.62–99.97% per week; complaints in the 99.62% and 99.71% weeks.
  4. SLOs: place-order 99.9% availability, 99% under 1 s; order-status 99.5%; rolling 28 days.
  5. Error budget policy (2.c), signed by the payments and orders leads and the product manager.
  6. Dashboard (2.e) generated by Sloth from a 20-line definition.

Result: for the first time everyone can see that the service is spending its budget about 2.5× too fast.

Weeks 3–4: alert and respond (Modules 3–5)#

  1. Burn-rate alerts (2.d) replace 19 of the 23 rules. Kept: disk will fill in 4 h, certificate expiry, DB replication stopped, Kafka consumer lag (freshness).
  2. Black-box probe (3.b) for place-order with a test account, from three regions.
  3. Runbooks (4.b) for each remaining alert, with the generic mitigations (4.c) — rollback, flag off, drain a zone, payments failover — written as copy-pasteable commands.
  4. Rotation (4.a): orders and inventory teams merge rotations: 9 people, primary and secondary, a stipend.
  5. Incident process (5.a–5.b): severity table, /incident command, IC rotation shared with two other teams. Postmortems (5.c) for the four past incidents, written retroactively.

Result: pages fall from ~45 to ~9 a month, nearly all actionable.

Weeks 5–6: stop the bleeding (Module 6)#

The postmortems point to the same weaknesses:

  1. Timeouts and deadlines (6.a): payments client had a 30 s timeout; now 2.5 s with the request deadline propagated; inventory 300 ms.
  2. Retries (6.b): three layers retried payments (27×). Now only the orders client retries, with full jitter and a 10% retry budget; idempotency keys on payment calls.
  3. Breaker and bulkhead (6.c) around payments; inventory gets its own connection pool.
  4. Load shedding (6.d): concurrency limit per pod; order-status (sheddable) shed before place-order (critical).
  5. Degraded mode (6.f): if inventory is down, accept orders and reserve stock asynchronously (agreed with product: a small oversell risk is better than no orders). Graceful shutdown fixed — deploys had been causing 502s.

Weeks 7–8: change safely (Module 8)#

  1. Pipeline (8.a): build once, image by digest, signed; deploy on merge.
  2. Canary (8.b): Argo Rollouts, 1% → 5% → 25% → 50% → 100% with error-ratio and latency analysis against a fresh baseline.
  3. Flags (8.c): OpenFeature with kill switches for the two expensive features; config changes staged by zone.
  4. Kubernetes (8.d): 6 replicas, topology spread across 3 zones, PDB minAvailable: 80%, startup/readiness/liveness probes fixed (liveness had been calling the DB), GOMEMLIMIT, no CPU limit.
  5. GitOps (8.e): manifests in Git, Argo CD with self-heal; Terraform for the DB with prevent_destroy.

Weeks 9–10: survive loss (Modules 7 and 9)#

  1. Capacity (7.d, 7.f): an open-loop k6 ramp finds 95 orders/s per pod at SLO; Black Friday forecast 620 orders/s → 6 pods are not enough: minReplicas: 9 on the day, HPA to 24; DB connection limit is the true bottleneck → PgBouncer added.
  2. Database (9.c): a synchronous standby in a second zone (RPO 0 in-region); replica lag alerting and lag-aware reads for order-status; the next migration done as expand/contract.
  3. Backups (9.a): WAL archiving and daily base backups to another account with object lock; automated weekly restore test — the first one fails (missing extension in the restore image), is fixed, and passes at 34 minutes.
  4. DR (9.b): warm standby in a second region for the DB, pilot light for the app; RPO 1 min, RTO 30 min.
  5. Hidden dependencies (9.d): the payments mTLS client certificate expires in 26 days and is renewed by hand — automated with cert-manager.

Weeks 11–12: prove it (Modules 10 and 11)#

  1. Chaos (10.a, 10.b): staging experiments for payments 503s, inventory latency and pod loss; one finds that the breaker’s fallback threw on a nil cache — fixed. Monthly production experiment: kill one zone’s pods.
  2. Game day (10.c): production DB failover at 10:00 on a Tuesday: 41 s to new primary, 20 s of errors from stale pool connections → pool max lifetime and retry on connection errors.
  3. Wheel of misfortune with each new on-call engineer.
  4. PRR (11.a): passes with two should-fix items (region failover not yet tested in production; one runbook unverified).

The result#

MeasureBeforeAfter 12 weeks
Place-order availability (28 d)99.71%99.95%
Pages per month~45 (70% noise)~7 (95% actionable)
Deploysweekly, manual~6 per day, canaried
Change failure rate~25%~3% (most caught at 1–5% canary)
Time to roll back20–40 min~2 min, automatic
Restore testedneverweekly, 34 min
Incidents per month20.5, smaller

None of these changes was clever. The improvement came from doing the ordinary things, in the order the evidence pointed to.

Code#

Every month the team publishes a one-page SLO report. This program generates it from daily counts — the artefact that keeps the SLO and the error budget policy in front of everyone.

Go
// sloreport.go — a monthly SLO and error budget report for orders-api.
package main

import (
	"fmt"
	"math/rand"
	"strings"
)

type day struct {
	total, bad int
	note       string
}

func main() {
	const slo = 0.999
	const background = 4000 // one request in 4,000 fails for ordinary reasons (0.025%)
	r := rand.New(rand.NewSource(28))
	days := make([]day, 28)
	for i := range days {
		total := 2_300_000 + r.Intn(200_000)
		days[i] = day{total: total, bad: total / background}
	}
	days[6].bad += 9000
	days[6].note = "INC-301: payments latency, breaker opened, fallback queue"
	days[19].bad += 3000
	days[19].note = "canary aborted at 5% (v2026.11.19-2)"

	var total, bad int
	for _, d := range days {
		total += d.total
		bad += d.bad
	}
	sli := 1 - float64(bad)/float64(total)
	budget := (1 - slo) * float64(total)
	used := float64(bad) / budget

	fmt.Println("orders-api — place-order availability — 28 days ending 2026-11-28")
	fmt.Printf("SLO %.1f%%   SLI %.4f%%   budget used %.0f%%   remaining %.0f%%\n\n", slo*100, sli*100, used*100, (1-used)*100)

	// Burn-down sparkline: remaining budget at the end of each day.
	marks := []rune("▁▂▃▄▅▆▇█")
	var spark strings.Builder
	cum := 0
	for _, d := range days {
		cum += d.bad
		rem := 1 - float64(cum)/budget
		if rem < 0 {
			rem = 0
		}
		spark.WriteRune(marks[int(rem*float64(len(marks)-1))])
	}
	fmt.Println("budget remaining, day by day: " + spark.String())

	fmt.Println("\nwhere the budget went:")
	ordinary := 0
	for i, d := range days {
		base := d.total / background
		ordinary += base
		if d.note != "" {
			fmt.Printf("  day %2d  %5.1f%% of budget  %s\n", i+1, 100*float64(d.bad-base)/budget, d.note)
		}
	}
	fmt.Printf("  background errors: %.1f%% of budget\n", 100*float64(ordinary)/budget)

	level := "normal (policy level 1)"
	switch {
	case used >= 1:
		level = "FREEZE (policy level 3)"
	case used >= 0.5:
		level = "caution (policy level 2)"
	}
	fmt.Printf("\npolicy status: %s\n", level)
	fmt.Println("open action items: 3 (2 P1, 1 P2) — see postmortem tracker")
}

Remember this#

  • Order matters: measure (SLOs) → alert and respond → stop the bleeding → change safely → survive loss → prove it.
  • Let postmortems and the error budget decide what to fix first.
  • Most of the gain comes from ordinary practices applied consistently, not clever engineering.
  • Publish an SLO report monthly; it keeps the policy alive.

Try it#

  1. Run sloreport.go. Add an incident that takes 60% of the budget on day 25. What does the policy status say?
  2. Write the twelve-week plan for a service you know, using this lesson’s structure. What would your weeks 1–2 find?
  3. Pick the one change from weeks 5–6 that would most help your service, and do it this week.

Check yourself#

  1. Why start with SLOs rather than with resilience patterns?
  2. Which incidents in the starting point did weeks 5–6 address, and how?
  3. What did the first automated restore test find, and why is that typical?
  4. Which result in the final table matters most to users?

Sources#

This lesson draws on every earlier lesson; the sources are listed there. The structure follows the Google SRE workbook’s case studies:

↑↓ navigate↵ openesc close

100% drag to pan · scroll or pinch to zoom · double-click to zoom in