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.

Setting SLOs

Module 2 Lesson 2.b 45 min Difficulty 3/5

Prerequisites 2.a, 1.d

The idea in one minute#

An SLO is a target for an SLI over a window: 99.9% of checkout requests succeed within 1 s, measured over a rolling 28 days. Choose the target from what the service has actually achieved and what users need, not from ambition. Choose a rolling window (usually 28 or 30 days) so the budget does not magically reset on the first of the month. Write the SLO down in a short document with an owner, so it is a decision rather than a dashboard.

Start loose and tighten. An SLO that is always red is ignored; an SLO that is always green with a huge margin protects nobody.

An analogy#

A train timetable promise: “95% of trains arrive within 5 minutes of schedule, measured over the last four weeks.” It is achievable, it is about what passengers feel, it says how “late” is judged, and a single bad Monday does not reset it.

A picture#

flowchart TB
  H[":i-activity: <b>Historical SLI</b><br/><small>last 4–12 weeks</small>"] --> P["Propose target<br/><small>slightly below history</small>"]
  N[":i-users: <b>User needs</b><br/><small>complaints, churn, contracts</small>"] --> P
  D[":i-network: <b>Dependency limits</b><br/><small>product of hard deps</small>"] --> P
  P --> W["Pick window<br/><small>rolling 28 days</small>"]
  W --> DOC[":i-file-text: <b>SLO document</b><br/><small>owner, SLI, target, policy</small>"]
  DOC --> R["Review quarterly<br/><small>tighten, loosen, retire</small>"]
  R --> P
  class H,N,D neutral
  class P,W queue
  class DOC memory
  class R io

How it really works#

Choosing the number#

  1. Measure first. Compute the SLI over the last 4–12 weeks, per week. Look at the spread, not only the average.
  2. Set the first target a little below what you achieved in a typical (not your best) month. If you achieved 99.93%, 99.95%, 99.82% and 99.96%, start at 99.9% — the 99.82% month would have been a budget overspend that teaches you something.
  3. Check against users. Did the 99.82% month cause complaints? If yes, the target needs to be at least that strict. If nobody noticed even 99.5%, you may be over-targeting.
  4. Check against dependencies. Is it achievable given the critical path (1.b)?
  5. Avoid absurd precision. 99.9%, 99.5%, 99% are enough; 99.937% invites argument and suggests a precision your measurement does not have.

Aspirational versus achievable. Some teams keep two numbers: the SLO they hold themselves to now, and the one they are engineering towards. Only the first drives alerts and policy.

Choosing the window#

WindowProsCons
Rolling 28 or 30 daysNo reset cliff; always reflects the last month; 28 days has the same weekdays every windowBudget “comes back” slowly after an incident
Calendar monthMatches business reporting, SLA billingA big outage on the 30th is forgotten on the 1st; teams game the reset
Rolling 7 daysFast feedbackToo noisy for low-traffic services; budget tiny
QuarterMatches planning cyclesToo slow to drive day-to-day decisions

Use a rolling 28-day window for engineering decisions, and calendar windows only where a contract demands it.

Latency SLOs#

Latency needs a threshold and a percentage, and often two of them:

90% of checkout requests complete in < 300 ms      (typical experience)
99% of checkout requests complete in < 1000 ms     (the tail)

Implement them with histograms (counts per latency bucket) so the “good” count is requests in buckets ≤ threshold. Pick thresholds that coincide with histogram bucket boundaries, otherwise you are interpolating.

SLOs for things that are not request/response#

ServiceSLIExample SLO
Nightly batch jobRuns that finished by 06:00 with correct row counts95% of days over a quarter
Event pipelineEvents processed within 5 min of publish99% of events over 28 days
Search indexReads served from an index < 10 min old99.5% of reads
Object storeObjects readable after write99.999999999% (durability, measured by scrubbing)

Dependencies and internal services#

An internal service with other teams as users needs an SLO too — it is how they decide whether to treat it as a hard dependency. A service’s SLO should be looser than each of its critical dependencies’ (they need roughly one more nine), or it will spend its budget on their failures.

The SLO document#

A one-page document per service. A template:

Service:        checkout-api
Owner:          payments team (SRE contact: @sre-payments)
Users:          web and mobile shoppers
Journey:        Pay for a cart

SLI 1 — availability
  Spec:  Checkout requests that do not fail on the server side.
  Impl:  Edge LB logs, path=/v1/checkout, method=POST.
         good  = status in [200..499] except 429, and response sent
         valid = all, minus 400/401/403/404/422 and synthetic traffic (header x-synthetic)
SLO:    99.9% over a rolling 28 days            → error budget 0.1% ≈ 40 min

SLI 2 — latency
  Spec:  Checkout requests that complete quickly.
  Impl:  Edge LB request_time histogram, same filters, good = < 1.0 s
SLO:    99% over a rolling 28 days

Rationale:  Last 12 weeks: 99.91–99.97% availability; complaints began at ~99.7%.
            Hard deps: payments (99.95%), inventory DB (99.99%).
Error budget policy: see 2.c
Alerting:   multiwindow burn rate (2.d)
Reviewed:   quarterly; next review 2027-01-15
Approved:   payments eng lead, product manager, SRE lead

The signatures matter. An SLO that the product owner has not agreed to will not survive the first time it blocks a launch.

A worked example#

Twelve weeks of checkout data, weekly availability:

99.95 99.97 99.93 99.81 99.96 99.94 99.98 99.92 99.70 99.95 99.96 99.94
  • Typical week: ~99.95%. Worst weeks: 99.70% (complaints, a known incident) and 99.81% (no complaints).
  • A 99.95% SLO is missed in eight of the nine rolling four-week windows — always red, so it would be ignored.
  • A 99.9% SLO is missed only in the four windows that contain week 9, the week users complained about. The 99.81% week, which nobody noticed, stays within budget.
  • Decision: 99.9% now; aspirational 99.95% after the canary work lands.

The program checks the rolling 28-day window (four weeks) against several candidate targets, which is how the decision above was made.

Code#

Go
// slochoice.go — evaluate candidate SLO targets against historical weekly SLIs over a rolling window.
package main

import "fmt"

func main() {
	// Weekly availability (%) for 12 weeks, and requests per week.
	weekly := []float64{99.95, 99.97, 99.93, 99.81, 99.96, 99.94, 99.98, 99.92, 99.70, 99.95, 99.96, 99.94}
	const reqPerWeek = 2_000_000.0
	const windowWeeks = 4 // rolling 28 days

	candidates := []float64{99.5, 99.9, 99.95, 99.99}
	fmt.Printf("%-8s", "target")
	for i := windowWeeks; i <= len(weekly); i++ {
		fmt.Printf(" wk%-4d", i)
	}
	fmt.Println(" violated")

	for _, target := range candidates {
		fmt.Printf("%-8.2f", target)
		violations := 0
		for end := windowWeeks; end <= len(weekly); end++ {
			var good, total float64
			for _, w := range weekly[end-windowWeeks : end] {
				good += reqPerWeek * w / 100
				total += reqPerWeek
			}
			sli := 100 * good / total
			mark := "  ok  "
			if sli < target {
				mark = " MISS "
				violations++
			}
			fmt.Printf("%s ", mark)
		}
		fmt.Printf(" %d of %d windows\n", violations, len(weekly)-windowWeeks+1)
	}
	fmt.Println("\nPick the target that is violated when users were actually hurt — and not otherwise.")
}

Remember this#

  • SLO = SLI + target + window. Start from history, check against users and dependencies.
  • Use a rolling 28-day window for engineering decisions.
  • Latency SLOs are “X% under T”, often two of them; align T with histogram buckets.
  • Write a one-page SLO document with an owner, rationale, policy link and sign-off.
  • Review quarterly: tighten when users need it, loosen when nobody notices.

Try it#

  1. Run slochoice.go. Remove week 9 (the 99.70% week). Which target would you choose now?
  2. Fill in the SLO template for a service you know. Which line was hardest to fill?
  3. Write an SLO for a nightly batch job you depend on.

Check yourself#

  1. Why is a rolling window better than a calendar month for engineering decisions?
  2. Why should the first SLO be set slightly below historical performance?
  3. Why should latency thresholds sit on histogram bucket boundaries?
  4. Who should sign an SLO document, and why does it matter?

Sources#

↑↓ navigate↵ openesc close

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