05. Reliability / Lesson 4 of 4
Observability
See inside a running system with logs, metrics and traces.
- 8 min
- Beginner
- 9 steps
- Time to find cause4 hours (bad)
- Error budget left—
- Request
- Health check
- Failed request
Step 1 of 9: Users say checkout is slow. Why?
Read every step as text
Step 1: Users say checkout is slow. Why?
Checkout passes through a gateway, an orders service, a payments service and a database. Support gets messages: "checkout takes ages". Nobody can see where the time goes.
The team opens servers one by one and guesses. Say it takes about 4 hours to find the cause, and users found the problem first.
Observability means you can ask new questions about a running system and answer them from the data it already produces.
Step 2: Logs: a diary of what happened
Each service writes a line for every important event, ideally as structured JSON with a request id. At 1,000,000 requests a day and 3 lines of about 500 bytes each, that is 1.5 GB a day.
Send them all to one searchable store. Searching one request id now finds the slow line in minutes, say 40, not hours. Logs say what happened in detail, but they are bulky and hard to total up.
Never log passwords, card numbers or tokens. Logs are copied around and kept for months.
Step 3: Metrics: numbers over time
A metric is a number sampled at a steady pace: requests per second, errors, memory. Sampled every 10 seconds, one metric is only 8,640 points a day, tiny beside 1.5 GB of logs.
Metrics are cheap to keep for a year and quick to graph, so they tell you that something is wrong and where to look, such as "payments latency rose at 12:04". They do not explain the single request.
Do not put unbounded values such as user_id in metric labels. Each value makes a new series, and a million of them break the store.
Step 4: Traces: the path of one request
A trace follows one request through every service. Each step is a span with a start and a length. This checkout took 2,300 ms: gateway 30, orders 120, payments 2,100, inventory 50.
One look shows payments is the slow span, about 91% of the time. Keeping every trace is costly, so systems often keep 1% (10,000 a day here) plus every slow or failed one.
Pass the trace id along in a header (W3C
traceparent), so every service adds its spans to the same trace.Step 5: Dashboards: the health of the system on one screen
A dashboard draws the metrics as graphs the team can read at a glance: requests, errors and latency, with one panel per service.
Show percentiles, not just the average. If p50 is 180 ms, p95 900 ms and p99 2.3 s, then 1 request in 100 takes more than 2.3 s, and an average would hide them.
Keep one overview dashboard for the whole service and link each panel to a more detailed one.
Step 6: Four signals that cover most problems
If you can watch only four things per service, watch the golden signals: latency (how long), traffic (how much), errors (how many fail) and saturation (how full the thing is).
Here: p99 latency 2.3 s, traffic 40 requests a second at the evening peak, errors 5% and payments' connection pool 95% full. Saturation near 100% is the warning that comes before a failure.
Latency, traffic and errors show what users feel. Saturation shows what is about to hurt them.
Step 7: SLI, SLO and the error budget
An SLI is a measure of what users feel, for example the share of checkouts that succeed in under 1 s. An SLO is the target: say 99.9% over 30 days.
Over a month that is 30,000,000 requests, so
30,000,000 × 0.1% = 30,000may be bad. That is the error budget. While budget remains, ship features; when it runs out, fix reliability first.100% is the wrong target: it costs far too much and users cannot tell the difference after about 99.99%.
Step 8: Alerts that matter: wake people only for user pain
Alerting on "CPU is 80%" wakes people for things users never feel. Alert on symptoms instead: budget burning too fast. Today 5% of 40 requests a second are bad, which is 2 a second. The budget of 30,000 would be gone in
30,000 ÷ 2 = 15,000 s, about 4.2 hours.Page when it would be gone within, say, 6 hours. This one fires about 5 minutes in, after only 600 bad requests, and 98% of the budget is still there. Every page needs a clear action.
Too many alerts and people start to ignore them. If a page needs no action, delete it or turn it into a ticket.
Step 9: Observability in one picture
Logs tell what happened, metrics tell that something changed and where, and traces show the path of one request. Dashboards and the four golden signals show health at a glance.
An SLO turns "fast enough" into a number, the error budget says how much failure is allowed, and alerts fire on user pain so the team finds problems before the users do.