Sub topic 8
Error budgets: how much a target allows to fail
This chapter assumes you know what an SLI and an SLO are, can read simple Python, and can do arithmetic on rates and durations. An SLO (service level objective) is a target for an SLI (service level indicator), which is a measured quantity such as the share of requests that succeed or finish within a time limit.
What an error budget is
An SLO of 99.9% says that 99.9% of events must be good. It also says that 0.1% may be bad. That 0.1% is the error budget: the amount of failure the target allows over a stated window.
The budget turns a target into a quantity you can spend. Releases, migrations, experiments and incidents all consume it. When the budget is nearly gone, the team slows risky changes. When plenty is left, the team can ship faster.
Computing a time-based budget
For an availability SLO, the budget is the window length multiplied by the allowed failure fraction.
# Error budget for a 99.9% availability SLO over 30 days
slo = 0.999
window_minutes = 30 * 24 * 60
error_budget_minutes = window_minutes * (1 - slo)
print(round(error_budget_minutes, 1)) # 43.2A 30-day window has 43,200 minutes. Multiplying by 0.001 gives 43.2 minutes of allowed unavailability.
| SLO | Allowed failure | Budget over 30 days |
|---|---|---|
| 99% | 1% | 432 minutes |
| 99.9% | 0.1% | 43.2 minutes |
| 99.99% | 0.01% | 4.32 minutes |
Each extra nine cuts the budget by a factor of ten. A budget of 4.32 minutes is smaller than the time many teams need to notice an incident and respond. Choose the number of nines from what users need, not from what sounds impressive.
Request-based budgets
Most latency targets count requests, not minutes. Suppose the SLO is that 99% of requests finish within 300 ms. The budget is then 1% of requests in the window. If the service handles 100 million requests in 30 days, it may serve 1 million slow or failed requests before it breaks the SLO.
Request-based budgets handle uneven traffic better than time-based ones. A five-minute outage at 3 a.m. affects few requests. The same outage at peak affects many. A request count reflects that difference and a minute count does not.
A request counts against the budget if it fails or if it is slower than the latency threshold. This links the budget back to the percentile targets from earlier chapters. A p99 target of 300 ms is the same statement as "at most 1% of requests may exceed 300 ms".
Tracking the burn rate
The burn rate is how fast the budget is being consumed compared with a steady pace. A burn rate of 1 uses exactly the whole budget by the end of the window. A burn rate of 10 would exhaust a 30-day budget in 3 days.
def burn_rate(bad_events, total_events, slo):
allowed_bad_fraction = 1 - slo
observed_bad_fraction = bad_events / total_events
return observed_bad_fraction / allowed_bad_fraction
# 600 slow or failed requests out of 100,000 in the last hour
print(round(burn_rate(600, 100_000, 0.999), 1)) # 6.0The observed bad fraction is 0.6%. The allowed fraction is 0.1%. The ratio is 6, so the service is spending its budget six times faster than planned.
Alerts based on burn rate work better than alerts on a single failed request. A high burn rate over a short window pages someone quickly. A modest burn rate over a longer window opens a ticket.
Common errors
- Setting the SLO at 100%. The budget is zero, so any change is a violation. No dependency you rely on is perfect either.
- Ignoring dependencies. If your service depends on a database with a 99.9% SLO, your own availability cannot exceed it unless you add redundancy or fallbacks.
- Counting only outages. Slow responses past the threshold also spend budget. Measure both.
- Using a window that hides problems. A very long window lets a bad week disappear. A very short one makes the budget swing wildly. Thirty days, or a rolling four weeks, is a common compromise.
- Treating the budget as a goal to use up. The budget is a limit. Finishing a window with budget left is fine.
Using the budget in decisions
A budget makes trade-offs explicit. If a deployment has a known risk of two minutes of degraded service and 20 minutes of budget remain, the team can decide whether the feature is worth it. If 3 minutes remain, the answer changes. The same arithmetic applies to planned maintenance and load tests in production.
Exercise
A service has a 99.95% availability SLO over 30 days. (a) How many minutes of unavailability does the error budget allow? (b) The service handles 200 million requests in that window. How many failed requests are allowed? (c) In the last hour, 1,000 of 500,000 requests failed. What is the burn rate?
Show answer
(a) The window is 43,200 minutes and the allowed failure fraction is 0.0005, so the budget is 43,200 0.0005 = 21.6 minutes. (b) 200,000,000 0.0005 = 100,000 failed requests. (c) The observed bad fraction is 1,000 / 500,000 = 0.002, and the allowed fraction is 0.0005, so the burn rate is 0.002 / 0.0005 = 4. The budget is being spent four times faster than planned.