← Back to Home

🎯 SLIs, SLOs and Error Budgets

SLIs, SLOs and error budgets in practice: why averages and histogram percentiles mislead, a simulated month comparing alert strategies, burn-rate alerting, and Prometheus rules.

"How reliable should this service be?" is usually answered with a feeling: "very", "always up", "five nines". None of those can be measured, alerted on, or traded off against shipping features. Service level objectives turn the feeling into a number, and the number into decisions: when to page someone at 3 a.m., when to slow down releases, and when reliability work can wait.

This article defines SLIs, SLOs, SLAs and error budgets, measures real latency to show why averages make poor indicators, and simulates a month of traffic to compare alerting strategies. One of them paged on 18 harmless blips and missed a slow burn entirely; burn-rate alerts caught every real incident and stayed quiet otherwise. It ends with Prometheus rules you can adapt.

It builds on Logs, Metrics and Traces with OpenTelemetry, which covered how to collect the data, and on the latency percentiles from System Design Estimation.

Why Not 100%?

Aiming for 100% availability sounds responsible. In practice it's impossible and the wrong goal:

The useful question is: how unreliable can this service be before users are unhappy? Everything below that line is an allowance you can spend on shipping features, running experiments and doing risky migrations. That allowance is the error budget.

SLI, SLO, SLA

Term What it is Example
SLI (indicator) A measurement of the service's behaviour, as a ratio of good events to valid events Share of HTTP requests answered successfully within 300 ms
SLO (objective) A target for the SLI over a time window 99.9% of requests good, over a rolling 30 days
Error budget 100% minus the SLO: how much "bad" is allowed 0.1% of requests, or about 43 minutes of full outage per 30 days
SLA (agreement) A contract with consequences, usually refunds 99.5% monthly, or customers get service credits

The SLA should be looser than the SLO. The SLO is your internal target; you want to notice and react long before you owe anyone money.

Choosing SLIs

Good SLIs measure what users experience, as a ratio of good events to valid events. For request-driven services, two cover most needs:

Other kinds of service need other indicators: freshness for data pipelines (share of records updated within 10 minutes), correctness for computation (share of results that pass validation), durability for storage (share of objects readable).

Where you measure matters. The closer to the user, the more honest. Server-side metrics miss requests that never reached the server, such as a broken load balancer, DNS failures or TLS errors. Load balancer logs are a good compromise; synthetic probes and real-user monitoring catch the rest. And exclude noise: health checks, internal batch traffic and synthetic tests shouldn't count towards a user-facing SLI.

Thresholds, Not Averages

A real Flask service where most requests are fast and a few are slow (a cold cache, a lock wait, a slow shard), measured with 4,000 requests:

4000 requests
mean latency:     90 ms   (describes no real request)
p50  true:     46 ms | from default histogram buckets:     47 ms
p90  true:    102 ms | from default histogram buckets:    101 ms
p95  true:    216 ms | from default histogram buckets:    216 ms
p99  true:   1302 ms | from default histogram buckets:   1826 ms
latency SLI:  90.0% of requests completed within 100 ms
latency SLI:  96.8% of requests completed within 300 ms
latency SLI:  97.8% of requests completed within 1000 ms

Three lessons:

  1. The mean hides the problem. At 90 ms it sits between the fast group (most requests) and the slow ones, and describes neither. The 2.2% of requests that took over a second, a real user problem, barely moves it.
  2. Percentiles from histograms are estimates. Prometheus stores latency in buckets, and histogram_quantile interpolates inside the bucket that holds the percentile. With the client library's default buckets (…, 0.5, 0.75, 1, 2.5 s), the p99 came out at 1,826 ms against a true 1,302 ms, a 40% error, because the bucket from 1 to 2.5 seconds is wide.
  3. A threshold SLI avoids both problems. "96.8% of requests within 300 ms" is a simple count, exact as long as 300 ms is a bucket boundary. Choose your histogram buckets to include your SLO thresholds.

The Nines and the Budget

An SLO's error budget, for a 30-day window:

SLO Allowed failure Full outage allowed per 30 days Bad requests per million
99% 1% 7 h 12 min 10,000
99.5% 0.5% 3 h 36 min 5,000
99.9% 0.1% 43 min 1,000
99.95% 0.05% 21.6 min 500
99.99% 0.01% 4.3 min 100

Two things to notice. At 99.99%, a single slow rollback uses the whole month; you need automated detection and rollback measured in seconds, and nothing done by hand. And a request-based SLO doesn't require a full outage to burn budget: 1% of requests failing for an afternoon costs as much as a few minutes down.

Use a rolling window (the last 30 days), not a calendar month: a calendar month resets on the 1st, so an outage on the 30th is forgotten two days later.

The Error Budget Policy

An SLO is only useful if the budget changes decisions. Teams write this down in advance, as an error budget policy agreed between product and engineering:

This makes the reliability conversation about numbers instead of opinions. "Can we ship this risky migration?" has an answer: "we have 70% of our budget left, so yes, with a rollback plan".

Alerting on Burn Rate

Alerting is where SLOs pay off most. The question an alert should answer is: "Are we spending the error budget so fast that someone needs to act now?"

The burn rate is how fast you're spending it, relative to a pace that would use exactly the whole budget in the window:

burn rate = observed error rate / allowed error rate

99.9% SLO, 0.1% allowed:  0.1% errors -> burn rate 1  (budget lasts exactly 30 days)
                           2% errors   -> burn rate 20 (budget gone in 1.5 days)
                           100% errors -> burn rate 1000 (budget gone in 43 minutes)

To compare strategies, here's a simulated 30-day month for a service with a 99.9% SLO and 1,000 requests per minute. Baseline errors are 0.02%; there are three real incidents and 20 harmless two-minute blips (3% errors during a deploy, say):

month: 43,200,000 requests, 45,001 errors = 104% of the error budget (43,200 errors allowed)

error rate > 1% over 5 min
   full outage: 100% errors for 10 min    detected after    0 min,   2.3% of budget spent by then, still firing    4 min after it ended
   partial: 2% errors for 6 hours         detected after    3 min,   0.1% of budget spent by then, still firing    2 min after it ended
   slow burn: 0.3% errors for 4 days      NOT DETECTED
   pages for the 20 harmless 2-minute blips: 18 | alerts outside real incidents: 18 | total alerts: 20

error rate > 0.1% (the SLO) over 5 min
   full outage: 100% errors for 10 min    detected after    0 min,   2.3% of budget spent by then, still firing    4 min after it ended
   partial: 2% errors for 6 hours         detected after    0 min,   0.0% of budget spent by then, still firing    4 min after it ended
   slow burn: 0.3% errors for 4 days      detected after    1 min,   0.0% of budget spent by then, still firing    1 min after it ended
   pages for the 20 harmless 2-minute blips: 20 | alerts outside real incidents: 20 | total alerts: 36

burn rate > 14.4 over 1 h
   full outage: 100% errors for 10 min    detected after    0 min,   2.3% of budget spent by then, still firing   59 min after it ended
   partial: 2% errors for 6 hours         detected after   43 min,   2.1% of budget spent by then, still firing   16 min after it ended
   slow burn: 0.3% errors for 4 days      NOT DETECTED
   pages for the 20 harmless 2-minute blips: 0 | alerts outside real incidents: 0 | total alerts: 2

multiwindow burn rate: pages
   full outage: 100% errors for 10 min    detected after    0 min,   2.3% of budget spent by then, still firing   29 min after it ended
   partial: 2% errors for 6 hours         detected after   43 min,   2.1% of budget spent by then, still firing   21 min after it ended
   slow burn: 0.3% errors for 4 days      NOT DETECTED
   pages for the 20 harmless 2-minute blips: 0 | alerts outside real incidents: 0 | total alerts: 2

multiwindow burn rate: tickets
   full outage: 100% errors for 10 min    detected after    2 min,   6.9% of budget spent by then, still firing  359 min after it ended
   partial: 2% errors for 6 hours         detected after  166 min,   7.6% of budget spent by then, still firing  345 min after it ended
   slow burn: 0.3% errors for 4 days      detected after 1210 min,   8.2% of budget spent by then, still firing  258 min after it ended
   pages for the 20 harmless 2-minute blips: 0 | alerts outside real incidents: 0 | total alerts: 3

The month as a whole missed its SLO (104% of the budget), so the alerts matter. Reading the results:

The thresholds come from deciding how much budget you can afford to lose before someone acts: 14.4 = 2% of a 30-day budget spent in one hour (0.02 × 720 hours / 1 hour). Change those percentages and the thresholds follow.

Work through your own numbers. The incident starts from a clean baseline:

Implementing It in Prometheus

Record the error ratio over each window once, then alert on the recorded series. This assumes a counter http_requests_total with a code label, as most HTTP instrumentation provides:

groups:
  - name: api-slo-recording
    rules:
      - record: job:slo_errors_per_request:ratio_rate5m
        expr: |
          sum(rate(http_requests_total{job="api", code=~"5.."}[5m]))
          /
          sum(rate(http_requests_total{job="api"}[5m]))
      - record: job:slo_errors_per_request:ratio_rate30m
        expr: |
          sum(rate(http_requests_total{job="api", code=~"5.."}[30m]))
          /
          sum(rate(http_requests_total{job="api"}[30m]))
      - record: job:slo_errors_per_request:ratio_rate1h
        expr: |
          sum(rate(http_requests_total{job="api", code=~"5.."}[1h]))
          /
          sum(rate(http_requests_total{job="api"}[1h]))
      - record: job:slo_errors_per_request:ratio_rate6h
        expr: |
          sum(rate(http_requests_total{job="api", code=~"5.."}[6h]))
          /
          sum(rate(http_requests_total{job="api"}[6h]))
      - record: job:slo_errors_per_request:ratio_rate3d
        expr: |
          sum(rate(http_requests_total{job="api", code=~"5.."}[3d]))
          /
          sum(rate(http_requests_total{job="api"}[3d]))

  - name: api-slo-alerts
    rules:
      - alert: ApiErrorBudgetFastBurn
        expr: |
          job:slo_errors_per_request:ratio_rate1h > (14.4 * 0.001)
          and
          job:slo_errors_per_request:ratio_rate5m > (14.4 * 0.001)
        labels:
          severity: page
        annotations:
          summary: "API is burning its 99.9% error budget 14x too fast (2% of the month's budget per hour)"
      - alert: ApiErrorBudgetSlowBurn
        expr: |
          job:slo_errors_per_request:ratio_rate6h > (6 * 0.001)
          and
          job:slo_errors_per_request:ratio_rate30m > (6 * 0.001)
        labels:
          severity: page
        annotations:
          summary: "API is burning its error budget 6x too fast (5% of the month's budget in 6 hours)"
      - alert: ApiErrorBudgetTicket
        expr: |
          job:slo_errors_per_request:ratio_rate3d > (1 * 0.001)
          and
          job:slo_errors_per_request:ratio_rate6h > (1 * 0.001)
        labels:
          severity: ticket
        annotations:
          summary: "API error budget burning faster than it refills over 3 days"

For a latency SLO, count good requests directly from the histogram bucket at your threshold, which must exist as a bucket boundary:

# share of requests slower than 300 ms over the last hour (the "bad" ratio for a latency SLO)
1 - (
  sum(rate(http_request_duration_seconds_bucket{job="api", le="0.3"}[1h]))
  /
  sum(rate(http_request_duration_seconds_count{job="api"}[1h]))
)

Writing these by hand for every service gets repetitive. Tools such as Sloth and Pyrra generate the recording and alerting rules from a short SLO definition, and OpenSLO is a vendor-neutral format for writing SLOs down.

Dependencies and Composition

Your service can't be more reliable than the things it needs on every request:

Ways to be more reliable than a dependency: cache its answers (#0037), degrade gracefully when it's down (show the page without recommendations), make the call asynchronous, or retry with hedging (#0038). And publish SLOs for your own service so that the teams depending on you can do the same calculation.

Common Mistakes

Key Takeaways

Copied to clipboard!