# SLOs, error budgets and on-call

Decide how reliable is reliable enough: pick SLIs users feel, set SLOs, turn them into error budgets, alert on burn rate instead of every error, and write runbooks that make on-call calm.

Course: [Monitoring](https://devops.rajeev.pro/courses/monitoring), lesson 8. About 30 minutes, intermediate. Source: https://devops.rajeev.pro/courses/monitoring/08-slos-and-on-call

## What you will learn

- Explain SLI, SLO and SLA, and how they differ
- Choose a good SLI for availability and for latency, and write it in PromQL
- Turn an SLO into an error budget in minutes and in requests
- Alert on error-budget burn rate with fast and slow windows
- Write a runbook and describe a healthy on-call rotation and a blameless postmortem

"Never down" is impossible and expensive, and users can't tell 99.99% from 100% anyway. An **SLO**
sets how reliable is reliable enough, and the gap to 100% becomes an **error budget** you're allowed
to spend. In this lesson you'll define SLIs in PromQL, turn SLOs into budgets, alert on burn rate
instead of every error, and set up the runbooks and on-call habits around them.

> **Video.** [SLIs, SLOs, SLAs, oh my! (class SRE implements DevOps)](https://www.youtube.com/watch?v=tEylFyxbDLE) (Google Cloud Tech)

## SLIs and SLOs

- **SLI** (service level indicator): a measurement of how users experience the service, almost
  always a ratio of **good events to all events**. "Share of requests that didn't fail."
- **SLO** (service level objective): the target for that SLI over a window. "99.9% over 30 days."
- **SLA** (service level agreement): a contract with customers, with money or credits if it's
  broken. It's usually looser than the SLO (say 99.5%), so you react long before you owe anything.
  Many internal services have SLOs and no SLA at all.

### Pick SLIs users feel

Good SLIs come from the golden signals in lesson 1, seen from the user's side:

| SLI type                  | Good event                                | All events   |
| ------------------------- | ----------------------------------------- | ------------ |
| Availability              | Requests that didn't return 5xx           | All requests |
| Latency                   | Requests faster than a threshold, say 1 s | All requests |
| Freshness (for pipelines) | Data updated in the last 10 minutes       | All checks   |

Measure as close to the user as you can: at the load balancer or ingress rather than deep inside one
service. And pick **two or three** SLIs per service, not twenty.

### Write the SLI in PromQL

The HotROD demo app from the tracing lesson exposes request counters and a latency histogram.
After a few ride bookings on the lab, its `/metrics` page showed:

```text
hotrod_requests_total{endpoint="GET_/dispatch",error="false"} 13
hotrod_requests_total{endpoint="GET_/dispatch",error="true"} 0
hotrod_request_latency_bucket{endpoint="GET_/dispatch",error="false",le="0.5"} 0
hotrod_request_latency_bucket{endpoint="GET_/dispatch",error="false",le="1"} 11
hotrod_request_latency_bucket{endpoint="GET_/dispatch",error="false",le="2.5"} 13
hotrod_request_latency_count{endpoint="GET_/dispatch",error="false"} 13
```

Read it as two SLIs:

- **Availability:** 13 requests, 0 with `error="true"`, so 13 / 13 = **100%**.
- **Latency (under 1 second):** the `le="1"` bucket counts requests that took 1 s or less: 11. All
  requests: 13. So 11 / 13 = **84.6%**. Against a "95% of bookings under 1 s" SLO, this service is
  failing badly, which matches the 330 ms SQL query and fourteen Redis calls you found in the trace.

As PromQL over a 30-day window, the same two SLIs are:

```promql
# Availability SLI
sum(rate(hotrod_requests_total{endpoint="GET_/dispatch", error="false"}[30d]))
  / sum(rate(hotrod_requests_total{endpoint="GET_/dispatch"}[30d]))

# Latency SLI: share of bookings finished within 1 second
sum(rate(hotrod_request_latency_bucket{endpoint="GET_/dispatch", le="1"}[30d]))
  / sum(rate(hotrod_request_latency_count{endpoint="GET_/dispatch"}[30d]))
```

The latency SLI only works if a bucket boundary sits exactly at your threshold. If your SLO says
300 ms and the histogram has buckets at 250 ms and 500 ms, add a 300 ms bucket first. Over 30
days these queries are heavy, so in practice you turn the 5-minute ratio into a recording rule and
average that.

### Choose the target

Start from what you achieve today, not from a wish. If the last three months were 99.95%, a 99.9%
SLO is honest and leaves room. Every extra nine is about ten times harder:

| SLO    | Error budget over 30 days |
| ------ | ------------------------- |
| 99%    | 7 hours 12 minutes        |
| 99.5%  | 3 hours 36 minutes        |
| 99.9%  | 43.2 minutes              |
| 99.95% | 21.6 minutes              |
| 99.99% | 4.3 minutes               |

You can't promise more than what you depend on. If your cloud database offers 99.95%, a 99.99% SLO
for the app on top of it is a wish.

## Error budgets

> **Figure.** Left: SLI is what you measure, good requests over all requests; SLO is the target, 99.9 percent over 30 days; error budget is what you may fail, 0.1 percent or 43.2 minutes per 30 days. Budget left means ship features and take risks; budget gone means freeze risky changes and spend the time on reliability. Right: a chart of budget remaining over 30 days. A dashed green line falls steadily to zero at day 30. A red line follows it, then drops sharply after a bad deploy, losing 10 percent in an hour. Below: burn rate 14.4 for 1 hour pages now, burn rate 1 to 6 for 6 hours or more opens a ticket.
>
> The budget is a resource you spend. Burn rate is how fast you're spending it.

The **error budget** is `1 - SLO`. For 99.9% that's 0.1% of requests, or 43.2 minutes of full
outage, in each 30-day window. If the service handles 10 million requests a month, the budget is
10,000 failed requests.

What makes the budget useful is an **error-budget policy** that both product and engineering signed
up to, for example:

1. **Budget above 50%:** release normally.
2. **Budget below 25%:** extra review for risky changes; no Friday deploys.
3. **Budget gone:** freeze feature releases (security fixes excepted) and put the team on
   reliability work until the 30-day window recovers.

Now the weekly argument has an answer. Product can see that last week's incident used 60% of the
month's budget. Ops can see that a quiet month has budget to spare for a risky migration.

## Alert on burn rate

The **burn rate** is how fast you're using budget compared with the steady pace that would use
exactly all of it by the end of the window:

- Burn rate **1**: errors at exactly the budget rate. The budget lasts the full 30 days.
- Burn rate **14.4**: 14.4 times too fast. The whole 30-day budget is gone in about 2 days; one hour
  at this rate uses **2%** of it.

In PromQL, burn rate is the error ratio divided by the budget:

```promql
(
  sum(rate(hotrod_requests_total{endpoint="GET_/dispatch", error="true"}[1h]))
  / sum(rate(hotrod_requests_total{endpoint="GET_/dispatch"}[1h]))
) / 0.001
```

The Google SRE workbook recommends **multiwindow, multi-burn-rate** alerts. Each alert checks a long
window (is this sustained?) and a short window (is it still happening right now?):

| Severity | Burn rate | Long window | Short window | Budget used when it fires |
| -------- | --------- | ----------- | ------------ | ------------------------- |
| Page     | 14.4      | 1 hour      | 5 minutes    | 2%                        |
| Page     | 6         | 6 hours     | 30 minutes   | 5%                        |
| Ticket   | 1         | 3 days      | 6 hours      | 10%                       |

```yaml
# slo-rules.yml
- alert: CheckoutErrorBudgetBurnFast
  expr: |
    (sum(rate(hotrod_requests_total{error="true"}[1h])) / sum(rate(hotrod_requests_total[1h]))) > (14.4 * 0.001)
    and
    (sum(rate(hotrod_requests_total{error="true"}[5m])) / sum(rate(hotrod_requests_total[5m]))) > (14.4 * 0.001)
  labels:
    severity: page
  annotations:
    summary: 'Checkout is burning its 30-day error budget 14x too fast'
    runbook_url: https://runbooks.example.com/checkout-error-budget
```

The short window makes the alert stop soon after the problem stops, instead of firing for another
hour. Writing these by hand for every service is tedious, so tools like **Sloth** generate the
recording rules and alerts from a short SLO file, and Grafana and most hosted tools have SLO
features built in.

## Runbooks and on-call

An alert is only as good as what happens after it fires.

### Runbooks

A **runbook** is a short page linked from the alert's `runbook_url`. It's written for someone tired,
new, or both:

```text
# TargetDown

What it means:  Prometheus could not scrape {{ job }} on {{ instance }} for 1 minute.
Impact check:   Is the service's error SLI dropping? (Grafana: "Checkout SLO" dashboard)
                Is it one instance or all of them? (Prometheus: up{job="..."})
First steps:    1. ssh / kubectl to the instance; is the process running?
                   systemctl status node_exporter   |   kubectl get pods -n <ns>
                2. If one instance is dead and others serve traffic: replace it, then investigate.
                3. If all are down: check the last deploy (rollback first, debug second).
Escalate to:    #team-platform; after 30 min, the platform lead on the on-call rota.
Last updated:   2026-11, by Rajeev
```

Keep runbooks in Git next to the alert rules, so they change together. When an alert fires and the
runbook was wrong or missing, fixing it is part of closing the incident.

### A healthy on-call rotation

- **A rota, not a hero.** At least 4 to 6 people, one week each, with a secondary as backup. The same
  person on call every night burns out.
- **Pages are rare and real.** Google's SRE book suggests at most about two incidents per 12-hour
  shift; more than that means the alerts need fixing, not the people.
- **Clear handover.** At the end of the week: what fired, what's still open, what was noisy.
- **Pay and time off** for on-call. It's work.

### Blameless postmortems

After a real incident, write a **postmortem**: what happened (a timeline, like the one in lesson 4),
the impact in SLO terms ("used 38% of the monthly budget"), why it happened, and actions with
owners. **Blameless** means you ask what in the system let a person make that mistake, not who made
it. People who fear blame hide problems, and hidden problems come back as bigger outages.

> **In production.** Start with one SLO for your most important user journey (login, checkout, search), measured at the edge. Put it on a dashboard everyone sees, agree the error-budget policy with product, and review SLOs every quarter. An SLO nobody looks at is just a number.

## Mission: Write an SLO for one service

Pick one service you know (or HotROD's /dispatch). Write a one-page SLO document with: the user journey, two SLIs (availability and latency) with their PromQL, a 30-day SLO for each with the reason for the number, the error budget in minutes and in requests at your traffic, a fast and a slow burn-rate alert, and a three-line error-budget policy.

- You need: HotROD's metrics: 13 requests, 0 errors, 11 under 1 s
- You'll have: ~/slo.md

```text
Service: ride booking (GET /dispatch)
SLI 1, availability:  requests with error="false" / all requests      SLO 99.9% over 30 days
SLI 2, latency:       requests with le="1" / all requests              SLO 95% under 1 s over 30 days
Error budget:         99.9% → 43.2 min/30 days; at 1M bookings/month → 1,000 failed bookings
Today:                availability 13/13 = 100%; latency 11/13 = 84.6%  → latency SLO already broken
Alerts:               burn rate 14.4 over 1h and 5m → page; burn rate 1 over 3d and 6h → ticket
Policy:               budget gone → feature freeze; fix the SQL query and batch the Redis calls first
```

That's the lab's real starting point: the service never failed, yet it's too slow for the SLO. An
SLO turns "it feels slow" into a number and a priority. Your service, numbers and reasons will
differ.

## Try it

- Work out the error budget in minutes for 99%, 99.9% and 99.99% over 30 days.
- Write the PromQL for "share of requests that did not return 5xx" over 30 days.
- Compute a latency SLI from a histogram's `le="1"` bucket and its `_count`.
- Calculate what burn rate 14.4 means in hours until the budget is gone.
- Write a one-page runbook for the TargetDown alert from lesson 4.
- Do the mini mission and keep `~/slo.md`.

## Quiz

1. What is the difference between an SLO and an SLA?
   - They are the same thing
   - **The SLO is your internal reliability target; the SLA is a contract with customers, usually looser, with penalties if broken** (answer)
   - The SLA is measured in Prometheus and the SLO is not
   Why: Teams set the SLO tighter than the SLA so they see trouble and react before a contract is broken and money is owed.

2. How much full downtime does a 99.9% availability SLO allow over 30 days?
   - About 4.3 minutes
   - **About 43.2 minutes** (answer)
   - About 7.2 hours
   Why: 30 days is 43,200 minutes. 0.1% of that is 43.2 minutes. 99% allows 7.2 hours, 99.99% about 4.3 minutes.

3. The error budget for this month is used up. What does a typical error-budget policy say?
   - Nothing changes
   - **Pause risky releases and spend the time on reliability until the budget recovers** (answer)
   - Lower the SLO to 90% so the budget comes back
   Why: The budget is how much unreliability you agreed to. When it's gone, feature work gives way to reliability work, which is what makes the SLO more than a number on a slide.

4. Why page on burn rate instead of "any error in the last 5 minutes"?
   - Burn rate is easier to type
   - **It pages only when errors are fast enough to threaten the SLO, so small blips don't wake anyone and real outages still page quickly** (answer)
   - Prometheus can't count errors
   Why: A burn rate of 14.4 over an hour uses 2% of a 30-day budget in that hour. That deserves a page; a burn rate of 0.5 doesn't.

5. What should a runbook contain?
   - The whole architecture of the company
   - **What the alert means, how to check impact, the first steps to fix or mitigate, and who to escalate to** (answer)
   - Only the alert's PromQL
   Why: A runbook is for a tired person at 3 a.m. It answers 'what is broken, how bad is it, what do I do first, who do I call', with commands they can copy.

## Resources

- [Service Level Objectives](https://sre.google/sre-book/service-level-objectives/) (Google SRE book)
- [Implementing SLOs](https://sre.google/workbook/implementing-slos/) (Google SRE workbook)
- [Alerting on SLOs (burn rates)](https://sre.google/workbook/alerting-on-slos/) (Google SRE workbook)
- [Postmortem culture](https://sre.google/sre-book/postmortem-culture/) (Google SRE book)
- [Sloth (generate SLO rules for Prometheus)](https://sloth.dev/) (Sloth)
- [OpenSLO specification](https://openslo.com/) (OpenSLO)
