Sub topic 7
Writing targets as SLIs, SLOs and SLAs
This chapter assumes you know what percentiles are (covered earlier), can read short Python snippets, and understand request/response systems with load balancers, services and databases. By the end you will be able to turn a vague requirement such as "the site should be fast" into a measurable target that a team can monitor and defend.
Three terms, three jobs
The three acronyms are often mixed up. Each one answers a different question.
- An SLI (service level indicator) is a measurement. It answers "what do we measure?"
- An SLO (service level objective) is an internal target for that measurement. It answers "how good do we want it to be?"
- An SLA (service level agreement) is a contract with customers. It answers "what do we owe them, and what happens if we miss?"
| Term | Owner | Example | Consequence of a miss |
|---|---|---|---|
| SLI | Engineering | Share of requests that finish in under 300 ms | None, it is only a number |
| SLO | Engineering and product | 99% of requests under 300 ms over 30 days | Teams slow releases and fix reliability |
| SLA | Business and legal | 99.5% monthly availability | Service credits or refunds |
An SLA should be looser than the SLO behind it. If the SLO is 99.9% and the SLA is 99.5%, the team gets a warning before the company owes anyone money.
Choosing good SLIs
A good SLI is expressed as a ratio of good events to valid events. This gives a value between 0% and 100% that is easy to compare against a target.
SLI = good events / valid eventsCommon SLIs for a request-driven service:
- Availability: requests that returned a non-error response, divided by all valid requests.
- Latency: requests that finished faster than a threshold, divided by all valid requests.
- Throughput or freshness: for batch or streaming systems, the share of jobs or records processed within a time limit.
Decide where you measure. A measurement at the load balancer sees what the service delivers. A measurement from a client or synthetic probe also includes the network and DNS, so it is closer to what users feel. Pick the point that matches the requirement, and write it down.
Writing an SLO
A complete SLO has four parts: the SLI, a threshold, a target percentage, and a time window.
> Rather than a sentence like "the API is fast", write: "99% of GET /search requests complete in under 300 ms, measured at the load balancer, over a rolling 30 days."
The next snippet computes a latency SLI from raw samples and checks it against an SLO.
latencies_ms = [12, 15, 14, 13, 16, 18, 20, 22, 250, 900]
threshold_ms = 300
slo_target = 0.99
good = sum(1 for x in latencies_ms if x <= threshold_ms)
sli = good / len(latencies_ms)
print(f"SLI = {sli:.2%}") # SLI = 90.00%
print("SLO met:", sli >= slo_target) # SLO met: FalseOne slow request out of ten is enough to fail a 99% objective on this tiny sample. With real traffic you have thousands of samples per minute, so the ratio is stable.
Where the numbers come from
Targets should come from user needs and from what the system can do, not from round numbers.
- Start from the requirement. If users abandon a page after about a second, the end-to-end budget must be well under that.
- Measure current behavior. An SLO far tighter than today's performance will fail at once. One far looser will never guide any decision.
- Choose a window. A rolling 30-day window smooths out single bad days. Shorter windows react faster but are noisier.
- Leave room between SLO and SLA, as described above.
Common errors
- Too many SLOs. Pick a few that reflect user experience, usually one availability and one latency objective per critical user journey.
- Counting invalid requests. Client errors such as a malformed request (HTTP 400) usually should not count against availability. Define which events are valid.
- Ignoring the percentile. "Under 300 ms" with no percentage is not a target. A p50 of 300 ms and a p99 of 300 ms describe very different systems.
- Making the SLA equal to the SLO. This leaves no margin, so every miss becomes a contractual breach.
- Measuring only the server. Server-side latency omits time spent in queues in front of the service and on the network.
The next chapter takes the gap between 100% and the SLO and turns it into an error budget.
Exercise
A checkout API has this SLO: "99% of requests complete in under 400 ms over 30 days." In one day, 2,000,000 valid requests arrive and 30,000 take longer than 400 ms. What is the latency SLI for that day, and does that day alone meet the SLO?
Show answer
Good requests = 2,000,000 - 30,000 = 1,970,000. SLI = 1,970,000 / 2,000,000 = 98.5%. That is below the 99% target, so this day alone misses it. The SLO is defined over 30 days, though, so the result for the window depends on the other days as well.
Exercise
A team sets its SLA at 99.9% availability and its internal SLO at 99.9% as well. Why is this a problem, and what would you change?
Show answer
There is no margin. Any month where the SLO is missed is also an SLA breach, so the company pays credits with no earlier warning. Set the SLO tighter than the SLA, for example SLO 99.95% with SLA 99.9%, so the team reacts before the contract is violated.