Sub topic 6
SLIs, SLOs, and SLAs
This chapter assumes you know what availability and the nines mean, and that you can turn a target like 99.9% into a downtime budget. It also assumes you have seen the difference between time-based and request-based measurement. You should be comfortable reading short Python snippets.
Three terms appear in almost every conversation about reliability: SLI, SLO, and SLA. People use them loosely, and the looseness causes real problems. A team promises a customer something it has never measured. Another team sets a target nobody can verify. A third treats a contract number as an engineering goal and has no margin left when things go wrong. This chapter separates the three terms, shows how to build each one, and covers the mistakes that come up most often.
The three terms
- A service level indicator (SLI) is a measurement of one aspect of service behavior. It is a number, usually a ratio of good events to valid events.
- A service level objective (SLO) is a target for an SLI over a time window. It is an internal goal that the engineering team commits to.
- A service level agreement (SLA) is a contract with consumers. It names a measurement, a threshold, and a consequence if the threshold is missed, usually a financial credit.
The dependency runs in one direction. You cannot have a meaningful SLO without an SLI to compare it to, and you cannot write an enforceable SLA without both.
| Term | What it is | Example | Who cares most | Consequence of missing it |
|---|---|---|---|---|
| SLI | A measured ratio | 99.93% of valid requests succeeded in under 300 ms | Engineers | None by itself |
| SLO | A target for the SLI over a window | At least 99.9% over a rolling 30 days | Engineers and product | Internal: slow down releases, spend effort on reliability |
| SLA | A contract with a remedy | Below 99.5% in a month, the customer gets a 10% credit | Customers, legal, finance | External: credits, refunds, termination rights |
Service level indicators
The good events over valid events form
The most useful SLI shape is a ratio:
SLI = good events / valid eventsThe result falls between 0 and 1, or 0% and 100%. Higher is better. This shape works for availability, latency, and correctness, and it connects directly to error budgets, which the next chapter covers. It also keeps the SLI intuitive, because 100% is perfect and 0% is total failure.
The definitions of "good" and "valid" do the real work. Valid events are the ones you hold yourself responsible for. Good events are the valid ones that met the user's expectations.
Choosing what counts
Consider an HTTP API. A reasonable definition:
- Valid: every request except those that failed because of a client mistake, meaning status codes 400 to 499.
- Good: a valid request that returned a status below 500 and finished within 300 ms.
Excluding 4xx responses is a judgment call. A 404 for a URL the client mistyped is not the service's fault. A 429 from your own rate limiter might be, depending on whether the client was within its quota. A 401 caused by a broken identity provider you operate is definitely your fault, even though it is a 4xx. You should write these rules down and review them, because they change the number.
The following program computes the SLI from a small sample of requests.
from dataclasses import dataclass
@dataclass
class Request:
status: int
latency_ms: float
def is_valid(request):
# Client errors (4xx) are not counted against the service.
return not 400 <= request.status < 500
def is_good(request):
return request.status < 500 and request.latency_ms <= 300
requests = [
Request(200, 120),
Request(200, 95),
Request(503, 40),
Request(404, 20),
Request(200, 450),
Request(201, 210),
]
valid = [r for r in requests if is_valid(r)]
good = [r for r in valid if is_good(r)]
print(len(good), len(valid), len(good) / len(valid))
# 3 5 0.6The 404 is dropped from the denominator. The 503 fails on status, and the 450 ms response fails on latency, so only three of the five valid requests are good.
Where to measure
The place you measure from changes what the SLI tells you.
- Server-side metrics are easy to collect, but they miss requests that never arrived, such as DNS failures, load balancer drops, or a certificate that expired.
- Load balancer logs catch more of what clients experience, including backend timeouts that the application never saw.
- Client-side telemetry is closest to the user's experience, but it is noisy. A user on a train with poor signal will register as a failure you cannot fix.
- Synthetic probes send scripted requests on a schedule from outside your network. They work well when traffic is low, because a service with ten requests an hour cannot produce a stable ratio. They test only the paths you scripted.
A common compromise is to take the SLI from the load balancer and to run synthetic probes alongside it as a cross-check.
Low traffic and empty windows
A ratio with zero valid events is undefined. If your service is idle for an hour, good / valid raises a division error. Decide in advance how to treat such windows. Skipping them is usually correct for rolling windows over days, but a service that is silent because it is completely broken looks identical to one that is merely unused. Probes help here, since they guarantee a minimum number of valid events.
Service level objectives
An SLO combines an SLI, a threshold, and a window. "99.9% of valid requests are good, measured over a rolling 30 days" has all three. Leaving out any one makes the statement ambiguous.
Choosing the window
- Calendar windows (a month, a quarter) match how contracts and reports work. The numbers reset on a fixed date, which makes the start of a month artificially forgiving and the end artificially tense.
- Rolling windows (the last 28 or 30 days) smooth over boundaries. A bad day affects the number for the following 30 days, not just until the calendar flips.
Short windows react quickly but are noisy, and a single incident can consume them. Long windows are stable but slow to show that a fix worked. Many teams use a rolling 28 or 30 days for the main SLO and shorter windows for alerting.
Choosing the target
Do not pick a target by aiming for the highest number you can imagine. Pick one using these inputs:
- What users actually notice. If a nightly batch tool is used twice a week, 99.99% serves nobody.
- What your dependencies allow. As the chapter on serial dependencies shows, a service cannot be more available than the product of the things it requires, unless it degrades gracefully when they fail.
- What you currently achieve. An SLO far above your history is a wish. An SLO far below it gives you no signal.
- What you can afford. Each extra nine costs more than the previous one, a theme developed in a later chapter.
An SLO of 100% is almost never right. It leaves no budget for deployments, and no real system achieves it. Users also cannot tell 100% from 99.99% when their own networks and devices fail more often than that.
Multiple SLOs per service
One service often needs several SLOs, usually at least availability and latency. Availability alone hides a service that returns errors rarely but takes ten seconds to respond. For a request-driven service, a typical set is:
- Availability: 99.9% of valid requests return a non-5xx status.
- Latency: 95% of valid requests complete in under 300 ms, and 99% under 1 s.
For data pipelines the equivalents are freshness (the output is no more than N minutes old) and correctness (the fraction of records processed without error). For storage, durability is a separate property from availability. A system can lose no data and still be unreachable.
Service level agreements
An SLA is a legal and commercial document. It differs from an SLO in several ways.
- It has consequences. Typically these are service credits, expressed as a percentage of the monthly bill, rather than cash refunds.
- It is usually looser than the internal SLO. If the SLO is 99.9%, the SLA might promise 99.5%. The gap gives the team room to fix a problem before money changes hands.
- It carries exclusions: scheduled maintenance windows, force majeure, customer-caused outages, and failures of the customer's own network.
- It defines how the measurement is made, who measures it, and how a customer files a claim. In many contracts the customer must request the credit within a fixed period, which means credits are paid out less often than outages occur.
Here is a simple credit schedule as code.
def sla_credit_percent(measured_availability):
if measured_availability >= 0.999:
return 0
if measured_availability >= 0.99:
return 10
if measured_availability >= 0.95:
return 25
return 100
for measured in (0.9995, 0.9985, 0.985, 0.90):
print(f"{measured:.2%}: {sla_credit_percent(measured)}% credit")
# 99.95%: 0% credit
# 99.85%: 10% credit
# 98.50%: 25% credit
# 90.00%: 100% creditNotice that a tiered schedule rewards the provider for staying just above a boundary. Customers sometimes negotiate for continuous schedules, where the credit grows smoothly with the shortfall.
Credits are not compensation
A 10% credit on a monthly bill rarely matches the damage an outage causes the customer. SLAs are a signal of seriousness and a limit on liability, not insurance. When you consume a third party's SLA, read the exclusions and the claim procedure before assuming the number protects you.
How the three fit together
The diagram shows the flow of information and the ordering of the thresholds.
The SLO should trip first. If the SLO is 99.9% and the SLA is 99.5%, the team gets warning and has time to react between the two lines. If the two numbers are equal, the first sign of trouble is a contract breach.
Checking an SLI against an SLO
A short function ties the measurement to the objective. It reports whether the SLO is met and how much room remains. This foreshadows error budgets, which the next chapter treats properly.
def evaluate_slo(good_events, valid_events, slo_target):
if valid_events == 0:
return None
sli = good_events / valid_events
return {"sli": sli, "meets_slo": sli >= slo_target}
print(evaluate_slo(9_993_000, 10_000_000, 0.999))
# {'sli': 0.9993, 'meets_slo': True}
print(evaluate_slo(9_985_000, 10_000_000, 0.999))
# {'sli': 0.9985, 'meets_slo': False}Common mistakes
- Measuring what is easy rather than what users feel. CPU load and process uptime are causes, not symptoms. An SLI should describe user-visible behavior.
- Averaging latency. A mean hides the slow tail. Use a ratio such as "the fraction of requests faster than 300 ms," or a high percentile.
- Setting the SLA equal to the SLO. This removes the buffer described above.
- Too many SLOs. If a service has twenty, nobody knows which matter. Start with a few that map to user journeys.
- Ignoring the denominator. A fixed count of errors means different things at 1,000 requests a day and 100 million. Always use ratios.
- Never revisiting targets. Usage, dependencies, and expectations change. Review SLOs at least every quarter.
- Unmeasured promises. An SLA with no matching SLI is a liability. Before signing, confirm that you already collect the data needed to prove compliance.
Exercises
Exercise
A service handled 4,000,000 requests in a 30-day window. Of these, 200,000 were 4xx client errors that you exclude as invalid. Of the remaining requests, 3,800 were 5xx errors and 1,200 were slower than the latency threshold but returned 200. The SLI counts a request as good only if it is fast and non-5xx. What is the SLI, and does it meet an SLO of 99.9%?
Show answer
Valid requests are 4,000,000 - 200,000 = 3,800,000. Bad requests are 3,800 + 1,200 = 5,000, so good requests are 3,795,000. The SLI is 3,795,000 / 3,800,000, which is about 0.99868, or 99.868%. That is below 99.9%, so the SLO is not met.
Exercise
Why should an SLA threshold normally be looser than the internal SLO for the same SLI, and what goes wrong if the two are equal?
Show answer
The gap between them gives the team time to notice a deteriorating SLI and fix it before a contract breach. If they are equal, the first signal of trouble is the missed SLA, so credits become owed with no earlier warning.
Exercise
A team reports "average latency is 120 ms, so we meet our latency target." Name one problem with this statement and one better SLI definition.
Show answer
A mean hides the slow tail, so a meaningful share of users could be waiting for seconds while the average stays low. A better SLI is the fraction of valid requests that complete within a threshold, such as 300 ms, with an SLO on that fraction, or a high percentile like p99.