Sikau

System design · Day 11 · about 40 min

Observability and SLOs

Percentiles beat averages; an error budget turns reliability into a number.

The average lied

Your dashboard says average response time is 120 ms — healthy. Yet learners complain the app freezes. Both are true: 98 requests took 50 ms and 2 took 3 seconds. The average hides the pain. That is why teams watch percentiles: p95 is the time that 95% of requests beat, p99 the time 99% beat.

Seeing inside a running system is observability, built from three signals: metrics (numbers over time, like p99), logs (what happened, with a request id) and traces (the path one request took across services). Metrics tell you *that* something is wrong; logs and traces tell you *why*.

Percentiles and error budgets

To find the p-th percentile, sort the numbers and take the value at rank ceil(p/100 × n) (the *nearest-rank* method). For 100 samples, p95 is the 95th smallest.

A service level objective (SLO) is a promise to yourself: "99.9% of requests succeed this month." The 0.1% you may fail is the error budget. Out of 1,000,000 requests that is 1,000 allowed failures. While budget remains, ship features boldly; once it is spent, slow down and fix reliability.

function percentile(values, p) {
  if (values.length === 0) return null;
  const sorted = [...values].sort((a, b) => a - b);
  const rank = Math.max(1, Math.ceil((p / 100) * sorted.length));
  return sorted[rank - 1];
}

function summarize(latencies) {
  return {
    count: latencies.length,
    p50: percentile(latencies, 50),
    p95: percentile(latencies, 95),
    p99: percentile(latencies, 99),
  };
}

function errorBudget({ slo, total, failed }) {
  const allowed = Math.round(total * (1 - slo));
  return { allowed, remaining: allowed - failed, ok: failed <= allowed };
}

The rest of this lesson

  • Nearest rankfill
  • Percentiles and budgetswrite code
  • Alerts that people can act onexplain
  • Reading a percentilepredict
  • Handling an alertorder
  • Badge quizquiz
  • What you learnedrecap