Courses System design · Part 3 · Lesson 5
Observability: Knowing When Your System Is Sick
The labs in this part showed how a system protects itself: a rate limiter turns extra traffic away, a circuit breaker stops calling a broken service, backpressure tells a fast producer to wait. On the bench you could see all of it. A real system runs on machines you never look at. Observability is everything you add so that you can still see what is happening, and find out why.
The three signals
- Metrics are numbers over time: requests per second, errors per minute, how full a queue is. They are cheap to keep for months, and good for charts and alerts. They tell you that something is wrong.
- Logs are lines of text about single events: “order 4182 failed: card declined”. They are expensive to keep, but they tell you what happened to one request.
- Traces follow one request through every service it touches, with the time spent in each. They tell you where the time went. A trace needs one request ID that every service passes along and writes into its logs.
A good order to add them: metrics first, then logs with a request ID in every line, then traces when you have more than a few services.
What to measure first: the four golden signals
Google’s SRE book suggests four numbers for every service that users touch:
- Latency: how long requests take. Measure failed requests separately: a fast error is not a fast success.
- Traffic: how many requests arrive, for example per second.
- Errors: how many fail, as a share of all requests.
- Saturation: how full the service is: CPU, memory, the length of its queue, free threads.
Saturation is the early warning. In the load balancer lab the slow server’s queue filled up long before requests were dropped; in the circuit breaker lab busy threads climbed to 6 of 6 before the client stopped working. A chart of queue length would have shown both early.
Averages lie; use percentiles
Say 100 requests come in. 95 take 50 ms and 5 take 2 seconds. The average is (95 × 50 + 5 × 2000) ÷ 100 ≈ 148 ms, which looks fine. But one user in twenty waits 2 seconds.
A percentile says “this share of requests was faster than X”. Here, p50 (the median) is 50 ms, p95 is 50 ms, and p99 is 2 seconds. Watch p95 and p99. The slow tail is usually where the real problem is: a full queue, a lock, a retry.
The tail grows with fan-out. If one page calls 20 services and each is slow only 1% of the time, the page is slow about 18% of the time (1 − 0.99²⁰).
SLI, SLO and the error budget
- An SLI (service level indicator) is a measured number, for example “the share of requests answered successfully within 300 ms”.
- An SLO (service level objective) is the target for it, for example “99.9% over 30 days”.
- The error budget is what the SLO allows to go wrong. 99.9% over 30 days allows 0.1% failures: about 43 minutes of full outage, or a longer time of partial errors. (See latency, throughput and availability.)
The budget turns arguments into a rule. Budget left: ship new features. Budget used up: slow down and fix reliability first.
Alerts worth waking up for
- Alert on symptoms users feel, not on causes. “Error rate above 2% for 5 minutes” or “the SLO budget is burning fast” is worth a phone call at 3 a.m. “CPU at 90%” is not, if users are still fine; put it on a dashboard.
- Every alert should need a human action. An alert that nobody acts on teaches people to ignore alerts.
- Include a link to a dashboard and a short note on what to check first.
In an interview
When you finish a design, say how you would know it works: “I’d track the four golden signals per service, p99 latency against an SLO of …, queue length for the workers, and a request ID through every log line.” It takes one minute and shows you have run real systems.
Summary
- Metrics say that, logs say what, traces say where.
- Start with latency, traffic, errors and saturation; saturation warns earliest.
- Use p95 and p99, not the average.
- Set an SLO, spend the error budget on purpose, and alert only on what users feel.