Sub topic 7
Making quality targets measurable: SLIs, SLOs, SLAs
This chapter assumes you can tell functional from non-functional requirements and can read short Python snippets. A non-functional requirement such as "the service must be fast" cannot be tested. This chapter shows how to turn it into a target you can measure.
Three terms, three jobs
- A service level indicator (SLI) is a measurement of behavior, such as the share of redirects that finish in under 100 ms.
- A service level objective (SLO) is a target for an SLI over a time window, such as 99% of redirects under 100 ms over 30 days.
- A service level agreement (SLA) is a contract with consequences, such as a refund if availability falls below 99.5% in a month.
The SLI is the thermometer, the SLO is the temperature you aim for, and the SLA is the penalty clause. Teams usually set the SLO tighter than the SLA, so they notice trouble before they owe anyone money.
Writing a good target
A usable target names four things: the quality, the measurement point, the threshold, and the window. Compare these two statements:
- Weak: "Redirects must be fast."
- Strong: "99% of redirects complete in under 100 ms, measured at the service edge over 30 days."
The strong version is NFR-1 from the URL shortener requirements:
non_functional:
- id: NFR-1
quality: latency
text: 99% of redirects complete in under 100 ms, measured at the service edge over 30 days.
- id: NFR-2
quality: availability
text: Redirects succeed for 99.9% of requests over a 30-day window.Most SLIs share one shape: good events divided by valid events. For latency, a good event is a request under the threshold. For availability, a good event is a request that did not fail.
From target to error budget
An SLO below 100% leaves room for failure. That room is the error budget. For availability over a window, it converts directly to downtime:
def downtime_budget_minutes(availability, days=30):
"""Minutes of allowed downtime for an availability target over a window."""
return (1 - availability) * days * 24 * 60
print(round(downtime_budget_minutes(0.999), 1)) # 43.2
print(round(downtime_budget_minutes(0.9999), 1)) # 4.3Moving from 99.9% to 99.99% cuts the budget from about 43 minutes to about 4 minutes. Each extra nine usually costs much more engineering effort, so pick the level users need, not the highest one.
Common errors
- No window. "99.9% available" means nothing until you say over what period.
- Averages for latency. A mean hides slow outliers. Use percentiles, covered in the next chapter.
- Measuring in the wrong place. Server-side timing misses network and load balancer delays. State where you measure.
- Setting the SLO equal to the SLA. You then have no warning before a breach.
- Targets nobody can measure. If you have no data source for the SLI, the SLO is only a wish.
Exercise
A team's SLO says 99.95% of requests succeed over 30 days. Roughly how many minutes of full downtime does this allow? Is a 99.9% SLA a sensible companion to this SLO?
Show answer
(1 - 0.9995) 30 24 * 60 = 21.6 minutes. Yes. The SLA (43.2 minutes of allowed downtime) is looser than the SLO, so the team gets an internal warning before it breaches the contract.