Sub topic 6
SLIs, SLOs, and SLAs
This chapter assumes you can read short Python snippets and know how a web service handles requests. It also assumes you have seen the nines notation and the difference between time-based and request-based measurement from earlier chapters.
Three terms, three jobs
Teams often use "SLA" for everything. The three terms name different things.
- A service level indicator (SLI) is a measurement of how the service behaves. Example: the fraction of requests that return a non-error response within 300 ms.
- A service level objective (SLO) is an internal target for an SLI over a window. Example: 99.9% of requests succeed over 30 days.
- A service level agreement (SLA) is a contract with customers. It states what the provider owes if the service falls below a stated level, usually service credits or refunds.
The SLI is the measurement. The SLO is the goal for that measurement. The SLA is the promise, with consequences attached.
Defining a good SLI
A useful SLI is a ratio of good events to valid events. That form gives a value between 0 and 1, and it maps directly to the request-based availability you have already seen.
Choose what "good" means from the user's point of view. A request that returns HTTP 200 with an empty page is not good. A request that takes 30 seconds is probably not good either. Decide which requests are valid too. Health checks from your own monitoring and malformed requests from clients usually do not count.
def sli(good_requests, valid_requests):
if valid_requests == 0:
return 1.0
return good_requests / valid_requests
print(sli(9_996_000, 10_000_000)) # 0.9996Setting the SLO
An SLO combines an SLI, a target, and a window. "99.9% of valid requests succeed, measured over a rolling 30 days" is complete. "99.9% availability" is not, because it leaves out the window and what counts as success.
Two rules help when choosing the target.
- Set it by what users need, not by what the system currently achieves. If users cannot tell 99.9% from 99.99%, do not pay for the extra nine.
- Do not aim for 100%. Every dependency you rely on is below 100%, and the cost of the last fraction grows without limit.
Most teams use several SLOs for one service, for example one for availability and one for latency.
Setting the SLA
The SLA should be looser than the SLO. If both are 99.9%, any miss of your internal goal is also a contractual breach. A common pattern is an internal SLO of 99.9% and a customer SLA of 99.5%. The gap gives you time to notice a problem and fix it before money is owed.
Read the fine print of any SLA you depend on. Typical clauses include:
- the measurement window, often a calendar month
- exclusions such as scheduled maintenance
- the remedy, usually a credit and rarely compensation for lost business
| Item | Audience | Consequence of missing it |
|---|---|---|
| SLI | Engineers | None. It is a measurement. |
| SLO | Engineering and product | Release pace slows, reliability work gets priority |
| SLA | Customers | Credits or other contractual remedies |
Checking an SLO in code
This sketch compares an observed SLI with an SLO and an SLA.
def evaluate(sli_value, slo=0.999, sla=0.995):
if sli_value >= slo:
return "healthy"
if sli_value >= sla:
return "SLO missed, SLA still met"
return "SLA breached"
for value in (0.9996, 0.998, 0.99):
print(value, evaluate(value))The output is healthy, SLO missed, SLA still met, and SLA breached. The middle case is where an internal SLO earns its keep. It warns you while customers are not yet owed anything.
Common mistakes
- Using an SLI that the server computes but the user never experiences, such as load balancer success when clients time out earlier.
- Writing an SLO with no window, so nobody can say whether it has been met.
- Setting the SLA equal to the SLO.
- Choosing an SLO nobody would act on. If missing it changes no decision, it is a dashboard number.
Exercise
A service has an SLO of 99.9% of valid requests succeeding over 30 days, and an SLA of 99.5%. Over the window it served 2,000,000 valid requests, of which 3,000 failed. What is the SLI, and is the SLO met? Is the SLA met?
Show answer
The SLI is (2,000,000 - 3,000) / 2,000,000 = 0.9985, or 99.85%. This is below the 99.9% SLO, so the SLO is missed. It is above the 99.5% SLA, so the SLA is still met and no credits are owed.