How to Choose Good SLIs for Your Service
Your dashboard is green: CPU at 40 percent, memory steady, every server running. Meanwhile, customers are posting that checkout keeps failing. Both can be true, because the dashboard describes the machines and customers feel the service. This lesson shows how to choose good SLIs, measurements that follow what users feel, and where to take them.
Start with what users feel
As lesson 4 explained, an SLI (service level indicator) measures how well users are served, and an SLO sets a target for it. A good SLI drops when users have a worse time and holds steady when they do not.
A user journey is the sequence of steps someone takes to get something done, such as searching, adding to the cart and paying. List your service's journeys, then pick the critical ones: those whose failure users notice at once or that cost money, such as checkout.
Next, define a good event. An event is usually one request, and a good one did what the user wanted. Web responses carry an HTTP status code, a three-digit result: the 200s mean success, the 400s mean the request itself was wrong (such as 404, not found) and the 500s, written 5xx, mean the server failed.
Then choose where to count, for example at the load balancer, the server that receives incoming requests and spreads them across your app's servers.
An SLI is a ratio of good to valid events
Every SLI has the same shape: good events divided by valid events, times 100. Valid events are the ones that should count at all. For a web service, that is usually every real user request, leaving out health checks, the small test requests a load balancer sends regularly to see whether each server is alive.
The result runs from 0 percent (no valid event was good) to 100 percent (every one was), so you can set an SLO and error budget on it as in lesson 4.
Health checks almost always succeed, so counting them as valid would flatter the SLI. Counting a 404 for a mistyped address as bad would let users' typos spend your error budget, so availability SLIs often count only 5xx responses as bad.
Pick SLIs by the type of service
Google's Site Reliability Workbook suggests a short menu for each type, and every item is still a share of good events:
- Request-driven services, such as a web API (a service other programs call over the web), answer each request as it arrives. Measure availability, the share answered successfully; latency, the share answered fast enough; and quality, the share answered in full rather than cut down, such as a product page shown without reviews because the reviews service was slow.
- Data pipelines process data behind the scenes, such as refreshing a sales dashboard every hour. Measure freshness, the share of data newer than a set age, such as one hour; correctness, the share of records processed into the right result; and throughput, the share of time the pipeline kept up with a target rate.
- Storage systems keep data for later. Measure durability, the share of data written that can still be read back, alongside availability and latency.
In the restaurant, availability is the food arriving, latency the wait, and quality the right dish, still hot.
Latency: count the requests that were fast enough
Latency is how long a request takes to answer. As Latency and Percentiles showed, an average blends a few very slow requests, the tail, into many fast ones until they vanish. With illustrative numbers: nine requests take 100 ms and one takes 2,000 ms. The average is 290 ms, under a 300 ms goal, yet one user in ten waited two seconds.
So make latency a ratio: requests answered in 300 ms or less, divided by all valid requests. Here that gives 90 percent, and the slow request counts. It matches the percentile view, where a percentile is the value a given share of requests stay at or below: if 99 percent take 300 ms or less, the 99th percentile (p99) is 300 ms or less.
Where to measure
The closer to the user you count, the more of their experience you see, including failures your servers never notice:
- Inside the server: your application's own metrics or logs. Detailed and easy to add, but a crashed server cannot count the requests it never answered.
- At the load balancer: it sees every request that reaches your service, including those a broken server dropped, which makes it a common SLI source. It misses failures before it, such as a broken record in DNS, the internet's directory from names to server addresses.
- In the client: code in the browser or app that reports what each user saw, often called real user monitoring. It is closest to what users feel, but it also counts weak Wi-Fi you cannot fix.
- Synthetic probes: a program that sends test requests from outside on a schedule, like the Try it below. It catches an outage even with no traffic, but checks only the paths you scripted.
Many teams start at the load balancer, then add probes or client data for critical journeys.
Common mistakes
Google's SRE book advises starting from what users care about, not from what is easy to measure. Most mistakes break that rule:
- Using CPU or memory as an SLI. They show how busy the machines are, like the lit stoves. CPU can sit at 20 percent while every request fails because the database is down. They measure saturation, one of the golden signals: keep them on dashboards for debugging and for capacity planning, which lesson 10 covers.
- Picking too many. With twenty SLIs, something is always red and nobody knows which number matters. The SRE book recommends a handful; start with one or two per critical journey, usually availability and latency.
- Measuring what is easy. "The process is running" takes one line of setup, yet a running process can still return errors to everyone. Ask of every SLI: if this number dropped, would users notice?
Check yourself
Checkout's average latency is 250 ms, under your 300 ms goal, yet users say it is often slow. How can both be true, and which SLI would show it?
A slow tail hides inside the fast average. The share of requests answered in 300 ms or less would fall, because it counts each slow request.
Your app servers' own metrics show almost no errors, but users cannot load the site. How can that be, and where should you measure?
Requests that never reached a working server were never counted by one. The load balancer, a probe or the client sees them, because each sits closer to the user.
A teammate proposes "CPU below 80 percent" as the SLI for checkout. What would you suggest instead, and why?
The share of checkout requests answered without a 5xx error, plus the share answered within 300 ms. CPU describes the machines: it can look healthy while every checkout fails.
Go deeper
- The beginner’s guide to Observability: a tour of the metrics, logs and traces you build SLIs from.