In one week a checkout service has eight short error blips and one 30 minute outage. A rule on raw errors pages 9 times, 8 of them for blips. A burn-rate rule on a 1 hour and a 5 minute window pages once, 60 s into the outage, and goes quiet 5 minutes after it ends.
Pick an alert rule, then drag how bad the outage is and count the pages. Then we build, piece by piece, the signals to measure, percentiles and histograms, what metrics cost, SLOs and error budgets, burn-rate alerts, logs and traces.
You need what a request and a server are and what a percentile is. Resiliency Patterns helps. We build the rest from zero.
Simulated in your browser, illustrative: 10,000 requests a minute, 0.05% normal errors, eight blips of 1 to 3 minutes at 2% to 8%, and a 30 minute outage on Thursday. SLO 99.9%. The burn-rate thresholds are the Google SRE Workbook's (14.4 over 1 hour, short window 1/12 of the long one).
Chapter 0
Follow one slow checkout through five services, and see which data finds the broken hop
It is 2 AM. Checkout requests take 2.3 s instead of 0.2 s. The request passes a gateway, an orders service, inventory, payments and a database query. Which one broke?
Monitoring tells you that something is wrong: a number crossed a line. Observability is how well you can find out why from the data the system already sends, with no new code. Three kinds of data do the work, often called the three pillars.
Metrics alone mislead here. Each service measures its latency from the moment a request arrives until it replies, and that includes the time it waits for the services it calls. So the gateway, orders and payments all report about 2.2 s. Every service on the path looks slow. A trace subtracts each span's children and gives its self time: the time it spent on its own work.
Bars are what each service reports. Add traces to see self time, then logs to read the culprit's own record. Then break a different hop.
Illustrative request: gateway 0 to 2,300 ms, orders 5 to 2,295 ms, and so on. Self time is a span's duration minus the time its child spans cover.
With the database broken, the trace gives the query 2,140 ms of self time. The gateway gets 10 ms, orders 20 ms and payments 55 ms. The log line on that span says why: a full table scan on a missing index.
Failure. Symptom: the team restarts payments, then orders, and nothing improves. Measure: self time per span on one slow trace. Cause: per-service latency includes downstream waits, so every caller looks guilty. Fix: trace the request; fix the span with the large self time.
Chapter 1
Watch two percent of slow requests leave the average calm and the p99 at over a second
The Google SRE book names four golden signals for a service that users call. Latency: how long a request takes, kept apart for successes and errors, since a fast error can hide a slow day. Traffic: demand, such as requests a second. Errors: the share of requests that fail. Saturation: how full the service is.
Latency needs care. Take 100 requests: 98 take 10 ms and 2 take 2,010 ms. The mean is 50 ms and looks fine. The p99, the latency that 99% of requests beat, is 2,010 ms. The mean averages the slow users away.
Blue bars are 20,000 request latencies on a log scale. Drag the slow share and watch which line moves. Then set how many requests one user makes.
Illustrative: fast requests are lognormal around 40 ms, slow ones around 1.2 s, sampled with a fixed seed. Percentiles use the nearest rank.
Why care about 1%? One page view often makes many requests. Call the share of requests slower than the p99 q, which is 0.01 by definition, and the requests one user makes n. The chance that a user meets the tail at least once is:
P equals one minus, one minus q, to the n.
One minus q is the chance one request is fast. Raise it to the n for all n to be fast. One minus that is the chance at least one is slow.
With made-up numbers: q = 0.01. For n = 20, P = 1 − 0.9920 = 18%. For n = 100, P = 63%. The "1% tail" is what most heavy users see.
So alert and set targets on percentiles, p99 or p99.9, and keep the p50 to show the typical case. The SRE book says the same: prefer percentiles to the mean.
Failure. Symptom: users complain of slow pages while the latency chart is flat. Measure: the p99 next to the mean. Cause: the dashboard plots the mean, and 2% of requests take a second. Fix: plot p50, p99 and p99.9 as separate lines.
Chapter 2
Load one disk and watch the service's RED numbers follow the disk's USE numbers
Two short methods tell you what to measure. Tom Wilkie's RED method is for each service: Rate (requests a second), Errors (failed requests a second) and Duration (the latency distribution). It shows what the users feel.
Brendan Gregg's USE method is for each resource: a CPU, a disk, a link, a connection pool. For each one, check Utilization (the share of time it was busy), Saturation (extra work it cannot serve yet, often a queue) and Errors (error events). RED finds the symptom. USE finds the resource behind it.
An operational law joins the two. Call the requests a resource completes each second its throughput X, and the seconds of work each one needs S.
U equals X times S.
This is the utilization law. Each second the disk does X reads of S seconds each, so it is busy for X times S of that second.
With made-up numbers: S = 0.005 s. At X = 100 reads a second, U = 0.5. At 180, U = 0.9. At 200, U = 1: the disk is full and the queue grows without end.
Latency does not grow in step with U. For one disk with random arrivals (an M/M/1 queue), the mean response time is S/(1 − U): 10 ms at U = 0.5, 50 ms at 0.9, 100 ms at 0.95. The last 10% of utilization costs ten times the latency.
Each request does one 5 ms disk read. Pink squares are the reads queued. Drag the rate and watch both panels.
Exact M/M/1 numbers: random arrivals, random service times, one disk. Errors are requests over a 250 ms client timeout. Illustrative rates.
Failure. Symptom: p99 doubles at noon every day, with no errors and no deploys. Measure: disk utilization on a 1 s scale, not a 1 min average. Cause: bursts reach 100% while the minute average reads 70%, as Gregg warns. Fix: watch saturation (queue length), and alert on the user's latency.
Chapter 3
Estimate a p95 from bucket counts and see the error grow with the bucket's width
A server sees millions of requests. It cannot keep every latency. A histogram keeps counters instead: how many requests took at most 0.1 s, at most 0.2 s, and so on. Each counter is a bucket, named by its upper bound. Prometheus stores the counts as cumulative.
To get a percentile back, find the bucket where the target rank falls. Then assume the requests in that bucket are spread evenly across it, and read off a value. Call the lower and upper bounds of that bucket l and u, the target rank r (the quantile times the total count), and the counts at or below each bound cl and cu.
Q-hat equals l, plus u minus l, times r minus c-l, over c-u minus c-l.
Count how far r sits into the bucket, as a share of the requests inside it. Move that same share of the way from l to u. This is what Prometheus's histogram_quantile does.
From the Prometheus docs: every request takes about 320 ms, and the buckets are 300 and 450 ms. All N requests sit in that bucket, so cl = 0, cu = N, r = 0.95N. Q̂ = 300 + 150 × 0.95 = 442.5 ms. The truth is near 320 ms.
Purple lines are bucket bounds. The solid line is the true p95; the dashed yellow line is the estimate. Drag the spike and change the layout.
10,000 simulated requests within a few percent of the spike. The estimate uses the interpolation above; the Go client's default buckets are 5 ms to 10 s.
Two rules follow. Put bucket bounds close together near the latency your SLO names, here 300 ms. And never average percentiles. Take four servers with equal traffic. Three have a p99 of 101 ms and one has 1,023 ms, so their average is 332 ms. The p99 of all their requests together is 808 ms. You can add histogram buckets across servers first. You cannot merge a summary, which computes quantiles on each client.
Failure. Symptom: the p99 chart sits flat at 487 ms through a real slowdown. Measure: which bucket the p99 falls in. Cause: the 250 to 500 ms bucket holds the whole tail, so the estimate cannot move inside it. Fix: add bounds near the SLO, or use native histograms.
Chapter 4
Count the time series one latency metric makes, and see one label turn thousands into billions
A metric has a name and labels: key-value pairs such as method="GET" or route="/cart". Each distinct set of label values is its own time series, stored and queried on its own. The Prometheus docs put it plainly: each labelset is an extra time series with RAM, CPU, disk and network costs.
The number of distinct values a label takes is its cardinality. Call the cardinality of label i ki and the bucket series of a histogram b, counting the catch-all +Inf bucket.
N equals b plus two, times the product over i of k-i.
_sum and _count series.Each label multiplies the count of combinations by its number of values. Each combination costs b plus 2 series. Only combinations that occur get stored, so N is a ceiling.
With made-up numbers: 4 methods, 30 routes, 6 status codes and 50 instances. N = 14 × 4 × 30 × 6 × 50 = 504,000. Add user_id with 100,000 users and the ceiling is 50.4 billion.
The purple bar is the series ceiling on a log scale. Switch labels on and off, and change the metric type.
Ceilings, from the product rule. The memory figure assumes 3 KB per active series, an illustrative round number, not a measured one.
The docs suggest keeping a metric's cardinality below 10, and keeping the few that pass 100 rare across the whole system. Their example: per-node filesystem metrics for 10,000 nodes make about 100,000 series, which is fine. Per-user quotas would make tens of millions.
Failure. Symptom: the metrics server runs out of memory a day after a deploy. Measure: series count per metric name. Cause: a new label holds request ids. Fix: drop the label; put ids in logs and traces, which hold one value per event.
Chapter 5
Turn an SLO into minutes of failure you may spend, then spend them on deploys and incidents
Three terms, from the Google SRE book. A service level indicator (SLI) is a measured quantity, for example the share of requests that succeed in under 300 ms. A service level objective (SLO) is a target for an SLI: 99.9% of requests over 30 days. A service level agreement (SLA) is a contract with consequences, such as refunds, if the provider misses the SLO in it.
The SRE book calls 100% both unrealistic and undesirable. The gap below 100% is the error budget: the failure you may spend on deploys, experiments and bad luck. Call the SLO s and the window length T.
B equals one minus s, times T.
One minus s is the share of the window that may fail. Multiply by T to get minutes. With a request-based SLI, multiply by the request count instead.
s = 0.999, T = 43,200 min. B = 0.001 × 43,200 = 43.2 min. Day 15, after 35 minutes of outage, 8.2 min remain. As requests: 10 million a month allows 10,000 failures.
| SLO | Budget in 30 days | Budget in 365 days |
|---|---|---|
| 99% | 7.2 hours | 3.65 days |
| 99.9% | 43.2 minutes | 8.76 hours |
| 99.95% | 21.6 minutes | 4.38 hours |
| 99.99% | 4.32 minutes | 52.6 minutes |
| 99.999% | 26 seconds | 5.26 minutes |
Hard dependencies cap the SLO. If a request needs a database at 99.95% and a platform at 99.99%, and their failures are independent, both work only 0.9995 × 0.9999 = 99.94% of the time. Ten hard dependencies at 99.9% each give 99.0%.
The purple bar is the budget left. Each event spends its minutes in red. Pick an SLO, then add events.
The policy steps (above 50%, 25 to 50%, under 25%, spent) are an example policy, illustrative. The SRE Workbook's example halts releases, apart from urgent and security fixes, once the 4-week budget is spent.
Failure. Symptom: the team meets its 99.99% SLO only in months with no deploys. Measure: budget spent per deploy. Cause: 4.32 minutes a month leaves room for two bad minutes and nothing else. Fix: set the SLO from what users need and the dependencies allow, often 99.9%.
Chapter 6
Turn an error ratio into a burn rate, and pair a long window with a short one so pages start fast and stop fast
A page wakes a person. The SRE book asks that every page be urgent and actionable, and that alerts watch symptoms users feel (errors, latency), not causes (CPU at 90%). Its load limit: two incidents per 12 hour shift, since each takes about six hours.
Which error ratio deserves a page? Compare it with the ratio the SLO allows. Call the error ratio you observe e and the SLO s.
b equals e over one minus s.
Divide the error ratio e by the allowed ratio. At b = 1 the budget lasts exactly the window. At b = 14.4 a 30 day budget is gone in 30 days divided by 14.4, about 50 hours.
e = 1.44%, s = 99.9%: b = 0.0144 / 0.001 = 14.4. An hour that spends 2 of the 43.2 budget minutes has b = 2 / 43.2 × 720 = 33.3, so the budget lasts 21.6 hours.
An alert on burn rate needs a window. How much budget is gone when it fires? Call the window length w and the SLO period T.
f equals b times w, over T.
Burning b times too fast for w hours spends b times w hours' worth of the budget. Divide by the T hours the budget covers.
The SRE Workbook's choices for a 99.9% SLO: b = 14.4 over w = 1 h spends 14.4 / 720 = 2% and pages. b = 6 over 6 h spends 5% and pages. b = 1 over 3 days spends 10% and opens a ticket.
A long window alone resets slowly: after a 30 minute outage, a 1 hour window stays above 14.4 for about 59 more minutes. The Workbook's fix is a short window, 1/12 of the long one, that must burn too. It drops within 5 minutes of the fix. At e = 100%, the 1 hour window passes 1.44% after 0.0144 h, about 52 s.
The red band is the incident. Purple lines are rolling error ratios; dashed lines are their thresholds. The teal band is when the rule pages.
Simulated, illustrative: 10,000 requests a minute, 0.05% normal errors, SLO 99.9%, 10 s steps. Thresholds and window pairs from the SRE Workbook, "Alerting on SLOs".
Try 1% for 4 hours. Neither 1 hour rule fires, since 1% is under 1.44%. The 6 hour pair fires after about 3.5 hours, with 5% of the budget gone.
Failure. Symptom: the on-call ignores pages that "always clear by themselves". Measure: pages a week, and the share that needed action. Cause: a threshold on minute-level errors fires on every blip. Fix: paired burn-rate windows; slow tiers go to tickets.
Chapter 7
Write logs a machine can query, join them by trace id, and price the volume before it prices you
A plain log line reads well and queries badly: ERROR payment failed for user 12345, amount=$50.00. To find every failed payment over $100 in the last hour, you parse text with regular expressions. A structured log writes each event as named fields, usually JSON, so a store can index and filter them.
json{"ts":"2026-11-26T01:47:23.412Z", "level":"ERROR", "service":"payments", "version":"2.3.1", "event":"payment_failed", "reason":"db_timeout", "amount_cents":5000, "duration_ms":2140, "trace_id":"4bf92f3577b34da6a3ce929d0e0e4736", "span_id":"00f067aa0ba902b7"}
The trace id is the field that matters most. Every service that touches the request writes the same id, so one query returns that request's lines from all of them. Never log passwords, tokens, card numbers or health data. Log at the boundaries (request in, call out, request done), not inside every function.
Volume grows fast. Call the requests a second R, the log lines per request n and the bytes per line s.
V equals R times n times s times eighty-six thousand four hundred.
Multiply the requests a second R by the lines n each writes and the bytes s per line. That is bytes a second; times 86,400 gives a day.
With made-up numbers: R = 2,000, n = 5, s = 500 bytes. V = 5 MB a second, 432 GB a day (decimal GB). Turn on DEBUG at 50 lines and it is 4.32 TB a day.
Bars are a day of logs by level. Pick a mode, then drag the traffic and the line size.
Illustrative: of 5 lines per request, 4.8 are INFO, 0.19 WARN and 0.01 ERROR. The price of $0.50 per ingested GB is a made-up round number, not a vendor's rate.
Sampling keeps the useful part. Keep every line of 10% of requests, chosen by trace id so each kept request stays whole, and every WARN and ERROR line. At 2,000 requests a second that is 59 GB a day instead of 432.
Failure. Symptom: the log bill triples in a week with flat traffic. Measure: bytes per day by service and level. Cause: someone left DEBUG on after an incident. Fix: a default level per environment, and an alert on log volume.
Chapter 8
Pass a trace id from hop to hop, then compare deciding at the start with deciding at the end
Google's Dapper paper (2010) set the model most tracers use. A trace is a tree of spans. Each span has a name, a start, an end, its own id and its parent's id. All spans of one request share a trace id. A span with no parent is the root.
For the tree to join up, each service passes the ids on. The W3C Trace Context standard puts them in one HTTP header, traceparent: a version, a 16 byte trace id, an 8 byte parent span id and a flags byte. The spec's example is 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01. The last bit of the flags says the caller may have recorded this trace.
At 10,000 requests a second, 8 spans each and 500 bytes a span, that is 40 MB a second, 3.46 TB a day. So tracers sample. Head sampling decides at the root, before it knows the outcome. Tail sampling waits until the trace ends, then keeps it by rule, for example every error and every slow trace. Call the head sampling probability p and the times a rare bug fires k.
P-keep equals one minus, one minus p, to the k.
The sampler flips its coin before the bug shows, so it keeps each of the k bad requests with chance p. One minus p to the k is the chance it drops them all.
With made-up numbers: k = 5, p = 0.01: P-keep = 1 − 0.995 = 4.9%. At Dapper's first rate, 1 in 1,024: 0.49%. A tail sampler that keeps every error keeps all 5.
Each dot is a trace: blue fine, yellow slow, red an error. Teal rings mark the kept ones. Pick a sampler, then drag how often the bug fires.
Illustrative: the read-out assumes 10,000 requests a second, 0.1% errors, 0.5% slow, 4 KB per trace and a 10 s tail decision wait (decimal GB). The dots show errors and slow traces 20 times more often than that, so you can see them.
Tail sampling has a price. The OpenTelemetry docs note it must be stateful and hold a lot of data: here every span for the 10 s wait, 400 MB in flight. Dapper moved to an adaptive head rate, a target number of traces per unit time, so quiet services sample more.
Failure. Symptom: a customer reports a failed payment, and no trace exists. Measure: the sampler on that route. Cause: 1% head sampling kept 1 in 100 errors. Fix: tail sampling for errors and slow traces, or a higher head rate on low-traffic routes.
Chapter 9
Break a live service four ways and read each failure off the signals, the burn rate and one trace
Here is a checkout service with one database, on a dashboard built from this lesson. The top row shows RED: rate, error ratio, and p50 and p99 latency. Then USE for the database disk. Then the burn rates on a 5 minute and a 1 hour window, with the paging rule from Chapter 6. At the bottom is the slowest recent request, as a trace.
One second of your time runs about four minutes of the service's. Break it, read the panels, and decide what you would do before you press Recover.
Press a fault. Watch which panel moves first, whether the burn rate pages, and what the trace blames.
Simulated, illustrative: 100 requests a second, one disk at 4 ms a query (9 ms slow, 10.5 ms without the index), a 1 s client timeout, SLO 99.9%. Each step is 10 s of service time.
Chapter 10
Keep the numbers, the defaults and the code in one place
Measure RED on every service and USE on every resource, with percentiles from well-placed histogram buckets. Keep labels bounded. Turn each SLO into a budget and page on its burn rate with paired windows. Write structured logs with a trace id, and keep the traces you will need with a tail rule for errors.
| Quantity | Rule | Worked number |
|---|---|---|
| Meeting the tail | 1 − (1 − q)n | q 1%, n 20: 18% |
| Utilization | U = X S; M/M/1 mean S/(1 − U) | 180 a second at 5 ms: 90%, 50 ms |
| Histogram estimate | interpolate inside the bucket | spike 320 ms, bucket 300 to 450: 442.5 ms |
| Series ceiling | (b + 2) × product of label counts | 14 × 4 × 30 × 6 × 50 = 504,000 |
| Error budget | (1 − s) T | 99.9%, 30 days: 43.2 min |
| Burn rate | e / (1 − s) | 1.44% at 99.9%: 14.4 |
| Budget spent at page | b w / T | 14.4 × 1 h / 720 h = 2% |
| Log volume | R n s × 86,400 | 2,000 × 5 × 500 B: 432 GB a day |
| Head sampling a rare bug | 1 − (1 − p)k | p 1%, k 5: 4.9% |
traceparent value is four hex fields of 2, 32, 16 and 2 characters.python# percentile from buckets, burn-rate paging and a tail sampling rule (sketch) def histogram_quantile(phi, bounds, cum): # bounds ascending, last = inf; cum = cumulative counts r = phi * cum[-1] i = next(j for j, c in enumerate(cum) if c >= r) if bounds[i] == float("inf"): return bounds[-2] lo, c_lo = (bounds[i-1], cum[i-1]) if i else (0.0, 0) return lo + (bounds[i] - lo) * (r - c_lo) / (cum[i] - c_lo) def burn(errors, requests, slo=0.999): return (errors / requests) / (1 - slo) if requests else 0.0 def should_page(win): # win["1h"] = (errors, requests), ... b = {k: burn(*v) for k, v in win.items()} return (b["1h"] >= 14.4 and b["5m"] >= 14.4) or (b["6h"] >= 6 and b["30m"] >= 6) def keep_trace(trace, slow_ms=1000, base=0.01): # runs after the trace ends if any(s.error for s in trace.spans): return True if trace.root.duration_ms > slow_ms: return True return int(trace.trace_id[-8:], 16) / 2**32 < base # same id, same decision everywhere
Now press Present or Teach and explain four things from memory. Explain why the mean hides the tail, with 1 minus 0.99 to the 20. Explain how a histogram estimate can be off by a whole bucket. Explain why a burn rate of 14.4 over an hour spends 2% of the budget, and why the short window matters. Explain why head sampling misses rare errors. Then go back to the hero and switch from Raw errors to the 1 h + 5 min rule.