The symptom and three explanations#
The example is fictional. The ledger-api alert fires when the 5xx ratio over ten minutes passes 0.8%. At 09:40 UTC it fired: the ratio had gone from about 0.5% to about 1%. The service has two routes. /balance is cheap and almost never fails. /transfer calls a payment network and fails about 2% of the time on an ordinary day. Three explanations fit the alert:
- More failures. Something made
/transferfail more often: a release, or the payment network. - Traffic fell. A client stopped calling
/balance, for example because the mobile app now reads balances from a cache, so the cheap successes that diluted the errors are gone. - The mix shifted. A partner's batch job started sending far more transfers, the route that always fails more, while total traffic stayed level.
Only the first is a problem with ledger-api. The other two change the ratio without any request failing more often than before. Choose the observation where explanations disagree
What each explanation predicts#
| Observation | More failures | Traffic fell | Mix shift |
|---|---|---|---|
| Error ratio, all routes | doubles | doubles | doubles |
| Error count | doubles | unchanged | rises |
| Total request count | unchanged | falls | unchanged |
| Error ratio of each route | /transfer rises | unchanged | unchanged |
| Request count of each route | unchanged | /balance falls | /transfer rises, /balance falls |
The first row is the alert, and it separates nothing. The error count, which is often the second graph people open, rises under both more failures and a mix shift, so it does not settle the question either. The fourth row is where "more failures" disagrees with both alternatives, and the third row then splits the two traffic explanations. An error ratio is a count of bad events divided by a count of all events, the usual shape of a service level indicator, so both counts need reading on their own before the ratio means anything. Implementing SLOs
The lab: one ratio, three causes#
The script draws ten minutes of requests for a baseline and for each explanation. Each request fails with a fixed probability for its route; only the more-failures world changes a probability. The other worlds change only how many requests each route receives. It needs Python 3.6 or later.
import random, sys
seed = int(sys.argv[1]) if len(sys.argv) > 1 else 3
# requests per 10 minutes and the chance each one fails, per route
worlds = {
"baseline": {"/balance": (8000, 0.001), "/transfer": (2000, 0.02)},
"more-failures": {"/balance": (8000, 0.001), "/transfer": (2000, 0.045)},
"traffic-fell": {"/balance": (1500, 0.001), "/transfer": (2000, 0.02)},
"mix-shift": {"/balance": (5500, 0.001), "/transfer": (4500, 0.02)},
}
print(f"{'world':<14} {'requests':>8} {'errors':>6} {'ratio':>6} | per route: requests, errors, ratio")
for name, routes in worlds.items():
rng = random.Random(seed)
rows = {}
for route, (n, p) in routes.items():
rows[route] = (n, sum(rng.random() < p for _ in range(n)))
total = sum(n for n, _ in rows.values())
errors = sum(e for _, e in rows.values())
detail = " ".join(f"{r} {n:>5} {e:>3} {e / n:5.2%}" for r, (n, e) in rows.items())
print(f"{name:<14} {total:>8} {errors:>6} {errors / total:6.2%} | {detail}")
Save it as ratio.py. Before running it, write down which world's /transfer ratio will move, and which world's total will fall. Python 3.11 printed:
world requests errors ratio | per route: requests, errors, ratio
baseline 10000 50 0.50% | /balance 8000 8 0.10% /transfer 2000 42 2.10%
more-failures 10000 97 0.97% | /balance 8000 8 0.10% /transfer 2000 89 4.45%
traffic-fell 3500 40 1.14% | /balance 1500 0 0.00% /transfer 2000 40 2.00%
mix-shift 10000 106 1.06% | /balance 5500 6 0.11% /transfer 4500 100 2.22%
All three worlds roughly doubled the overall ratio. The /transfer ratio rose only in the more-failures world, from 2.10% to 4.45%; in the other two it stayed within a few tenths of a percentage point of the baseline. The traffic-fell world is the only one whose total fell, and the mix-shift world is the only one with the same total and a different split. The mix-shift world also had more errors than the more-failures world, 106 against 97, without a single request becoming more likely to fail.
The prediction fails if a per-route ratio moves well outside its baseline noise in the traffic-fell or mix-shift world. Run python3 ratio.py 11 for different draws. The /balance ratio in the traffic-fell world moved from 0.10% to 0.00% in this run, which is eight errors against none: at counts that small a route's ratio wanders, so compare counts, not percentages, when either side is in single digits.
Read it on a real system#
With a Prometheus counter labelled by route and status code, read the two counts per route, then the ratio per route. These queries only read; use your own metric and label names. rate
sum by (route) (increase(http_requests_total{job="ledger-api", code=~"5.."}[10m]))
sum by (route) (increase(http_requests_total{job="ledger-api"}[10m]))
sum by (route) (rate(http_requests_total{job="ledger-api", code=~"5.."}[10m]))
/ sum by (route) (rate(http_requests_total{job="ledger-api"}[10m]))
Plot them over the day before as well as the hour around the alert. A ratio whose numerator is flat while its denominator falls is a traffic story, and the next question is who stopped calling.
On an Application Load Balancer, RequestCount and HTTPCode_Target_5XX_Count give the two totals per target group. RequestCount counts only requests for which the load balancer chose a target, and the target counts exclude errors the load balancer generated itself, so read HTTPCode_ELB_5XX_Count beside them. Application Load Balancer metrics
for m in RequestCount HTTPCode_Target_5XX_Count; do
aws cloudwatch get-metric-statistics --namespace AWS/ApplicationELB --metric-name "$m" \
--dimensions Name=LoadBalancer,Value=app/ledger-alb/0123456789abcdef \
Name=TargetGroup,Value=targetgroup/ledger-api/0123456789abcdef \
--start-time 2026-11-20T08:40:00Z --end-time 2026-11-20T10:40:00Z \
--period 600 --statistics Sum --output table
done
Load balancer metrics have no route dimension. For the per-route split, use the service's own metrics or its access logs.
Limits#
The split has to run along the dimension the traffic changed on. A route-level split misses a client that stopped sending one kind of request inside the same route, such as a health check or synthetic probe on /balance whose successes were part of the denominator. When the per-route ratios hold still and the totals still disagree with last week, split by client, tenant or user agent next.
Small counts make ratios unreliable. With ten requests an hour, one failure is a 10% error rate, which is why the SRE workbook treats low-traffic services and quiet periods separately in its alerting advice. Low-traffic services A ratio that doubles overnight while traffic falls to a tenth needs comparing with the same hour last week. Regression or weekly pattern?
The numerator can change meaning. A release that starts answering client cancellations with a 5xx status, or a proxy that starts answering slow requests with 504, raises the error count with no change in what users experience. Check what counted as an error before and after.
Retries feed both counts. A client that retries a persistently failing request three times sends four requests and four errors where one of each would have been, so the ratio overstates the share of user actions that failed, and it rises faster than that share when failures increase.
Questions#
Should the alert use the error ratio or the error count?
Each misleads in one direction: the ratio rises when good traffic falls, and the count rises when all traffic rises. Alerting on the ratio only above a minimum request count, and showing both counts beside the ratio, guards against both.
The error ratio spikes every night. Is something failing at night?
Probably not more than in the day. Fewer requests at night means each failure moves the ratio more, and nightly batch jobs often change the route mix. Compare per-route error counts at night with the same hours on previous nights before treating the spike as a fault.
If each route's error ratio is unchanged, is the service fine?
It means requests of each kind fail as often as before, so the alert came from what users sent. Something still changed, such as a client that stopped calling or a batch job that started, and it may matter to someone, but the investigation moves from the service to its callers.