Distributed Tracing and Incident Debugging
Overview
In a system with many services, one user click may touch twenty of them. Distributed tracing records the journey of a single request across all of them so you can see where time or errors occur.
Incident debugging is the calm, repeatable process of using metrics, traces and logs to fix a production problem fast.
Detailed Notes
What is distributed tracing
A trace is the full record of one request's journey. It is made of spans: one unit of work each, with a name, start time and duration, such as "pricing.getQuote 480 ms". A span that calls another is its parent, so spans form a tree. All spans share one trace ID.
Context propagation means passing the trace ID (and parent span ID) along with every call, usually in an HTTP header, so each service attaches its spans to the same trace. OpenTelemetry is a widely used open standard for creating and sending spans.
The problem it solves
Each team sees only its own service dashboard, and every one says "OK" while users wait 7 seconds. Teams then blame each other for hours. A trace shows the whole picture in one view.
How it works
A waterfall view shows timing and nesting. For example, a booking request of 1200 ms might show the gateway at 80 ms, then the booking service at 1100 ms, which contains inventory (150 ms), pricing (700 ms, of which 650 ms is its own database query) and payment (300 ms). The longest bar on the critical path, the pricing database, is where to look first.
Sampling. Keeping every trace is costly at high traffic, so keep a portion:
- Head-based: decide at the start (e.g. keep 1%). Cheap, but can miss rare slow or failing requests.
- Tail-based: decide after the request ends, keeping errors and slow ones. Better data, but needs buffering and more resources.
The incident workflow.
- Detect: an alert or user report.
- Triage: how bad, who is affected, how urgent?
- Mitigate first: stop the pain by rolling back the last release, shifting traffic or switching off a feature. Do not hunt for the perfect root cause while users suffer.
- Investigate: ask "what changed?" (deploys, config, traffic, dependencies). Follow the metrics, then a trace, then the logs.
- Fix and verify.
- Learn: write a blameless postmortem with timeline, root cause and follow-up actions. Blameless means examining how the system and process allowed the mistake, not punishing a person.
A simple example
A travel site's search occasionally took 12 seconds. Every service dashboard looked fine. A trace showed the search service calling the currency service once per hotel (200 calls) instead of once in total, a bug from a recent release. The team rolled back within minutes and fixed it later with one batch call.
System design example
Make every service pass the trace ID along (shared middleware helps), log it in every line, and keep error and slow traces when sampling. If one service forgets to forward the ID, the trace breaks into pieces. Most outages follow a change, so keep a deploy timeline next to dashboards and make rollback one click.
Summary
- A trace follows one request; spans are its steps; the trace ID ties them together.
- Context propagation must happen at every hop or the trace breaks.
- Sample wisely and always keep slow and failed traces.
- Mitigate first, investigate second, and learn through blameless postmortems.
Architecture Diagram
One trace ID follows the request from the user to the database.
- 1The gateway creates a trace ID for the incoming request.
- 2Each service passes the ID on and records its own span.
- 3Spans are collected and assembled into a waterfall.
- 4The engineer finds the slowest span and checks its logs.
Common Interview Questions
Chapter quiz
Monitoring and Observability · 4 questions
1.Which signal is best for finding which service in a chain is slow?
2.Why is user_id a poor metric label?
3.Why use p99 latency instead of the average?
4.What should an on-call engineer do first when a bad release is hurting users?
0 of 4 answered
Finished this lesson?
0 of 91 lessons done · 0% of the course

