Sub topic 7
Making quality targets measurable: SLIs, SLOs, SLAs
This chapter assumes you can read short Python snippets and know what a latency percentile is. You should also know that a service has requests that either succeed or fail. By the end you will be able to turn a vague quality wish such as "the service should be fast" into a requirement that you can measure and test.
Why "fast" and "reliable" are not requirements
A requirement like "redirects must be fast" cannot be tested. Two engineers will read it differently, and no one can say whether the system meets it. A usable quality requirement answers four questions:
- What is measured?
- Where is it measured?
- Over what period?
- What value counts as good enough?
Service level terminology gives each answer a place. It has three terms that are easy to confuse.
| Term | Full name | What it is | Who uses it |
|---|---|---|---|
| SLI | Service level indicator | A measurement of one aspect of behavior | Engineers |
| SLO | Service level objective | A target for an SLI over a window | Engineers and product owners |
| SLA | Service level agreement | A contract with consequences if a target is missed | Customers and the business |
An SLI is a number. An SLO is a goal for that number. An SLA is a promise, usually with money attached.
Service level indicators
An SLI is most useful when it is a ratio of good events to valid events:
SLI = good events / valid eventsThe result falls between 0 and 1, or 0% and 100%. Higher is always better, which makes SLIs easy to compare, graph and alert on.
Two decisions define an SLI:
- What is a valid event? Exclude traffic that is not the service's fault, such as requests that fail validation with a 400 response. If you count them, clients can lower your score.
- What is a good event? For availability, a good event might be a response with a status below 500. For latency, a good event might be a response sent in under 100 ms.
Choose the SLI that matches what the user experiences. A redirect service is judged on redirect success and redirect speed. CPU usage matters to operators, but users never see it, so it is a poor SLI.
The measurement point matters too. Measuring at the load balancer or edge includes network and queueing delays that measuring inside the application hides. Prefer a point close to the user, and state it in the requirement.
Service level objectives
An SLO adds a target and a time window to an SLI. The requirements file from the topic plan expresses this in its non-functional section:
service: url-shortener
functional:
- id: FR-1
text: A user can submit a long URL and receive a short URL.
- id: FR-2
text: Requesting a short URL redirects to the original long URL.
- id: FR-3
text: A user can delete a short URL they created.
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.
- id: NFR-3
quality: durability
text: A created short URL is never lost once creation has been acknowledged.
out_of_scope:
- Click analytics
- Custom domainsCheck NFR-1 against the four questions. The measurement is redirect duration. The place is the service edge. The period is 30 days. The good value is under 100 ms for 99% of requests. NFR-2 is stated the same way, with the SLI being the share of successful redirects.
NFR-3 is different. "Never lost" is a binary guarantee. It is testable through failure experiments and replication checks, but it is not a ratio over a window. Not every quality needs an SLO, but every quality needs a way to be verified.
Percentile targets are used for latency because averages hide slow requests. See the performance chapter for the details.
Rolling windows and calendar windows
A rolling window, such as the last 30 days, forgets old incidents gradually. A calendar window, such as each month, resets on a fixed date. Rolling windows are smoother for day-to-day decisions. Calendar windows line up with billing and reporting. Whichever you choose, write it into the requirement.
Error budgets
An SLO below 100% leaves room for failure, and that room is the error budget. A 99.9% target means 0.1% of events may be bad. Over time, this converts to a downtime budget:
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.3Each extra nine cuts the budget tenfold. Going from 99.9% to 99.99% shrinks 43.2 minutes to 4.3 minutes. That is less time than a typical human response to an alert, so it forces automated recovery.
Most real services measure the budget in requests, not minutes, because traffic is uneven. An outage at 3 a.m. costs fewer requests than one at noon.
valid_requests = 12_000_000
good_requests = 11_990_400
slo = 0.999
sli = good_requests / valid_requests
allowed_bad = round((1 - slo) * valid_requests)
actual_bad = valid_requests - good_requests
print(f"SLI: {sli:.5f}") # SLI: 0.99920
print(allowed_bad, actual_bad) # 12000 9600
print(f"budget used: {actual_bad / allowed_bad:.0%}") # budget used: 80%The SLI of 0.9992 meets the 0.999 SLO, and 80% of the budget is spent. Teams use this number to decide what to do next. With plenty of budget left, they can ship risky changes. With the budget nearly gone, they pause releases and fix reliability.
Service level agreements
An SLA is a contract. It names a target, a window, and a remedy, usually service credits or a refund. Three points separate it from an SLO:
- The SLA target is looser than the internal SLO. If you promise customers 99.9%, run internally to 99.95%. Then you get a warning before you owe anyone money.
- The SLA has legal wording about what counts as downtime, such as exclusions for scheduled maintenance.
- Missing an SLO triggers engineering work. Missing an SLA triggers a business consequence.
flowchart TDThe chain below shows how the three terms relate.
Common errors
- Targets with no window. "99.9% availability" means little without "over 30 days". A year-long window hides a bad month.
- Averages for latency. A mean of 30 ms can coexist with a 99th percentile of 250 ms.
- Counting what you cannot control. Including client mistakes in the valid events makes the SLI noisy and unfair.
- Too many SLOs. Pick a few that reflect user experience. Each SLO needs monitoring and a response plan.
- 100% targets. They leave no budget, cost enormous amounts, and are usually capped by the reliability of dependencies you do not control.
- SLO equal to SLA. There is no safety margin, so any miss becomes a contractual breach.
Exercise
A service handles 50,000,000 valid requests in a 30-day window. Its availability SLO is 99.95%. During the window, 18,000 requests fail. What is the SLI, and how much of the error budget has been used?
Show answer
The SLI is (50,000,000 - 18,000) / 50,000,000 = 0.99964, or 99.964%, which meets the SLO. The budget is (1 - 0.9995) x 50,000,000 = 25,000 bad requests. The service used 18,000 / 25,000 = 72% of it.
Exercise
Rewrite "the search page should load quickly and almost never fail" as two measurable requirements. Name the SLI, target, window and measurement point of each.
Show answer
Any answer with all four parts for both is acceptable. Example latency requirement: 95% of search page responses complete in under 300 ms, measured at the load balancer over a rolling 30 days. Example availability requirement: at least 99.9% of valid search requests return a status below 500, measured at the load balancer over a rolling 30 days.