Sub topic 7
Writing targets as SLIs, SLOs and SLAs
This chapter assumes you know what latency, throughput and percentiles are, and that you can read simple Python. You should also be comfortable with how a request moves through a load balancer, a service and a database. Earlier chapters showed how to turn product needs into numbers. Here you will write those numbers in a form that a team can measure, alert on and be held to.
Why "fast enough" is not a target
A sentence such as "the checkout API should be fast" cannot be tested. Two engineers will read it differently, and nobody can tell whether last week met it. A usable target answers four questions:
- What is measured? For example, the time from request received to response sent.
- Which requests count? For example, successful
POST /checkoutcalls. - What threshold is acceptable? For example, 300 ms.
- Over what window, and for what share of requests? For example, 99% of requests over 30 days.
SLIs, SLOs and SLAs are three terms that separate these answers into distinct pieces.
The three terms
| Term | Full name | What it is | Who it is for |
|---|---|---|---|
| SLI | Service level indicator | A measurement of behavior, such as the share of requests faster than 300 ms | Engineers and dashboards |
| SLO | Service level objective | A target for an SLI over a window, such as 99% over 30 days | The team that runs the service |
| SLA | Service level agreement | A contract that states consequences, such as credits, if a target is missed | Customers and the business |
The SLI is the ruler, the SLO is the line you draw on the ruler, and the SLA is the contract that says what happens if you cross the line. An SLA is normally looser than the internal SLO. That gap gives the team room to notice and fix a problem before it triggers a penalty.
Choosing SLIs
An SLI works best as a ratio of good events to valid events:
SLI = good events / valid events × 100%
This form has a useful property. It always falls between 0% and 100%, so different services can be compared and combined. A latency SLI then becomes "the proportion of valid requests that completed in under 300 ms". A percentile still appears, but through the threshold: "99% of requests under 300 ms" is the same statement as "the p99 is below 300 ms".
Common SLIs by service type:
| Service type | Typical SLIs |
|---|---|
| Request/response API | Availability (non-error responses), latency below a threshold |
| Data pipeline | Freshness (age of the newest data), throughput, correctness |
| Storage system | Durability, read and write latency, availability |
| Batch job | Completion before a deadline, success rate |
Three decisions shape every latency SLI.
Where to measure
You can measure at the application, at the load balancer, or at the client. Each sees a different latency.
- Application metrics miss time spent in queues before the process accepts the request, and they miss network time.
- Load balancer metrics include queueing at the service and are usually a good default for server-side SLIs.
- Client-side or synthetic measurements include DNS, network and rendering. They match the user experience best but are noisier and harder to attribute.
A common failure is measuring inside the application only. When the service is overloaded, requests wait in the accept queue, the application timer starts late, and the dashboard looks healthy while users wait.
Which requests are valid
Define what counts. Health checks, requests rejected for bad input (HTTP 4xx), and traffic from your own load tests usually should not count against the SLO. Requests that fail with 5xx errors are different. A fast error is not a good response, so it should count as bad, or be tracked in a separate availability SLI. Otherwise a service that fails instantly looks excellent on latency.
Which threshold
Pick the threshold from the user requirement and the latency budget from earlier chapters, not from what the service does today. If the budget gives the application service 80 ms at p99, the application-level SLI uses that threshold.
From SLI to SLO
An SLO adds a target ratio and a window:
> "99% of valid POST /checkout requests complete in under 300 ms, measured at the load balancer over a rolling 30 days."
That statement contains the metric, the scope, the threshold, the percentage and the window. Anyone can compute it from logs.
The following Python code computes this SLI from a list of latencies and checks it against the SLO.
def latency_sli(latencies_ms, threshold_ms):
"""Share of requests faster than or equal to the threshold."""
if not latencies_ms:
raise ValueError("no valid requests in the window")
good = sum(1 for x in latencies_ms if x <= threshold_ms)
return good / len(latencies_ms)
latencies_ms = [12, 15, 14, 13, 16, 18, 20, 22, 250, 900]
sli = latency_sli(latencies_ms, threshold_ms=300)
slo_target = 0.99
print(f"SLI = {sli:.1%}") # SLI = 90.0%
print("SLO met" if sli >= slo_target else "SLO missed") # SLO missedNine of the ten requests are under 300 ms, so the SLI is 90%, which falls short of 99%. The one request at 900 ms is enough to miss the target with a sample this small. In production the sample has millions of requests, so a single slow request does not matter. The ratio form still makes the result easy to read.
Several SLOs for one endpoint
A single percentile hides the shape of the distribution. Teams often set two latency objectives for the same endpoint:
| Objective | Threshold | Target share |
|---|---|---|
| Typical experience | 100 ms | 90% of requests |
| Tail experience | 300 ms | 99% of requests |
The first protects the common case. The second limits how bad the slow tail can get. If you only set the second, the median can drift from 40 ms to 250 ms without breaking anything.
Choosing the window
The window controls how the SLO behaves.
- A short window (for example 1 day) reacts quickly but is dominated by single incidents and traffic changes.
- A long window (for example 30 days) is smoother but forgives a bad day and reports problems late.
- Rolling windows avoid the cliff at the start of a calendar month. Calendar windows line up with billing and reporting.
Many teams use a 28-day or 30-day rolling window for the SLO, and a shorter window for alerting on how fast the budget is being used.
Setting the number
The percentage should reflect what users need and what the system can sustain. It should not be as high as possible. Each extra nine costs far more than the previous one, because it needs redundancy, careful releases and more engineering time. It also has diminishing value: if the user's phone network is only 99% reliable, a 99.999% backend adds little.
Start from a measured baseline. If last quarter's data shows 99.5% of requests under 300 ms, an SLO of 99.9% is a stretch goal that will be missed constantly, while 99% is probably too loose to catch regressions. Choose a value slightly below demonstrated performance, then tighten it as the system improves.
SLOs and SLAs together
An SLA is built on top of SLOs, with commercial terms added. A typical arrangement:
| Level | Target | Purpose |
|---|---|---|
| Internal SLO | 99.9% of requests under 300 ms | Engineering target, triggers alerts and action |
| External SLA | 99.5% of requests under 500 ms | Contract, triggers credits when missed |
Notice that the SLA has both a lower percentage and a looser threshold. The internal SLO is stricter on both, so the team has warning before the contract is at risk. Never publish an SLA you have not met in measured data for several months.
The diagram shows how the pieces relate.
Common mistakes
- Using averages as SLIs. An average of 128 ms can hide a p99 of 900 ms, as the percentile chapter showed. Use a threshold ratio or a percentile.
- Averaging percentiles. You cannot average the p99 of ten servers to get the fleet p99. Aggregate the underlying good and total counts instead, or merge histograms. The ratio form makes this easy: add up all good events and all valid events, then divide.
- Too many SLOs. Each objective needs a dashboard, an alert and an owner. Start with one availability SLI and one latency SLI per user-facing journey.
- Targets with no consequence. An SLO that nobody acts on is decoration. Decide in advance what happens when it is missed, for example pausing risky releases. The next chapter turns this into an error budget.
- Measuring only what is easy. Server-side latency is easy to collect, but it can stay green while users see slow pages. Add at least one measurement close to the user.
- Ignoring traffic mix. If 90% of traffic is cheap reads and 10% is expensive writes, a combined SLO can pass while writes are slow. Separate SLIs for distinct operations.
Example: writing a complete target
Suppose a product requirement says: "Search results should feel instant, and the system must handle the evening peak." Working through it:
- Requirement to threshold. Research shows users notice delays above about 200 ms, so the threshold is 200 ms.
- SLI. The proportion of valid
GET /searchrequests with status below 500 that complete in 200 ms or less, measured at the load balancer. - SLO. 99% over a rolling 28 days, plus 95% under 100 ms.
- Throughput condition. The SLO applies up to 3,000 requests per second. Above that, the service may shed load, and shed requests are counted as failures in the availability SLI.
- SLA. Not offered for the free tier. For paying customers, 99% under 400 ms monthly, with a service credit.
Step 4 matters. A latency target with no stated load is incomplete, because latency depends on load. Tie each latency SLO to the throughput range for which it holds.
Exercise
A service handled 4,000,000 valid requests this month. Of these, 3,960,000 finished in 250 ms or less. The SLO is "99% of requests under 250 ms". Compute the SLI, say whether the SLO was met, and explain why the average latency would not be a better SLI.
Show answer
SLI = 3,960,000 / 4,000,000 = 99.0%. The SLO requires at least 99%, so it was met, with no margin. The average latency is a poor SLI because a small number of very slow requests can leave the mean looking acceptable while a noticeable share of users wait too long. The ratio of good requests to valid requests measures what share of users had an acceptable experience, and it can be summed across servers.
Exercise
Your team's SLO is 99.9% of requests under 300 ms. A customer contract is being drafted. Propose an SLA and justify the gap between the SLA and the SLO.
Show answer
A reasonable SLA is looser than the SLO on at least one dimension, for example 99.5% of requests under 300 ms, or 99.9% under 500 ms. The gap gives the team time to detect a regression and fix it before it breaches the contract. It also accounts for measurement differences between your metrics and the customer's. Only commit to numbers that months of measured data show you can meet.