Module 4 · Testing, Incident Diagnosis, and System Design Review · Lesson 7 of 9
Production Incident Diagnosis with Metrics, Traces, and Logs
Diagnose before reading
After a release, p95 rises from 300 ms to four seconds while CPU and throughput stay flat. A teammate says, 'The SQL is slow.' Write two competing hypotheses and one observation that could disprove each. Do not treat deployment timing as a root-cause finding.
Write your answer first. Then use this trace to check the boundary you chose.
| Observation | Candidate explanation | Next discriminating check |
|---|---|---|
| Command spans are short, request time is long | Connection acquisition or another uncovered wait | Where does instrumentation start? Measure acquisition and inspect representative paths |
| Low CPU, long queues | Waiting on dependencies, permits or concurrency | Compare wait durations, worker activity and downstream throttling |
| One slow trace | One example of a slow path | Check frequency and population with metrics; consider sampling gaps |
| Normal average, rising p99 | Tail latency affecting a subset | Break down route/workload/region under the data policy |
Investigation loop
- state the user-visible symptom and affected scope;
- check whether the change is traffic-related, dependency-related, or release-related;
- form one falsifiable hypothesis;
- choose the cheapest signal that can disprove it;
- mitigate customer impact;
- preserve evidence for the deeper fix.
Start with the service-level symptom
Translate “the API is slow” into measurable boundaries:
- which routes, tenants, regions, and versions are affected;
- when the change began;
- latency percentile, error rate, and throughput before and after;
- whether queued or background work is also delayed;
- whether the dependency time is included in the observed latency.
Do not start by searching logs for arbitrary errors. First decide what a healthy request should look like.
Metrics: detect and bound the problem
Metrics are best for trends and comparisons. A useful first dashboard includes:
- request rate, failures, and p50/p95/p99 latency;
- in-flight requests and rate-limit rejections;
- thread-pool queue length and process CPU;
- managed heap size, allocation rate, and garbage-collection pauses;
- database connection-pool usage and command duration;
- outbound dependency duration and error rate;
- worker queue depth, dequeue rate, and oldest-item age.
Look for correlated changes. High latency with low CPU and an exhausted connection pool suggests waiting rather than CPU saturation, but does not alone identify its cause. Combine runtime counters, connection-acquisition evidence, representative traces and, when safe, thread stacks.
Traces: follow one slow path
A sufficiently instrumented and propagated distributed trace can help answer:
- where the request spent its time;
- which dependency or internal stage dominated;
- whether retries created repeated spans;
- whether baggage or correlation identifiers crossed service boundaries;
- whether the same operation crossed an asynchronous handoff.
Trace context must be propagated through supported transports; an asynchronous message may need a propagated parent context or span links according to its processing model. Baggage is optional contextual data, not automatically a recorded span attribute or an authorization source. Do not place secrets or personal data in baggage, and filter propagation across trust boundaries.
Compare representative slow traces with healthy traces for the same route and workload. Missing spans can reflect instrumentation gaps or sampling, not absence of work. One trace is an example, not proof of frequency, so return to metrics to estimate impact.
Logs: explain the decision and failure
Structured logs should add facts that metrics and traces do not carry. Prefer structured fields such as operation name, attempt number, outcome, duration and trace identifier. Include tenant/order identifiers only under an approved data policy with access and retention controls; pseudonymous IDs can still be sensitive. High-cardinality identifiers may be useful in logs/traces but are generally unsuitable as unbounded metric dimensions.
Avoid:
- interpolated messages that lose stable message-template fields; prefer structured logging templates with named parameters;
- secrets, access tokens, or full personal data;
- logging the same exception at every layer;
- unbounded high-cardinality fields in metric labels;
- success logs for every hot-path operation when traces already provide that detail.
An illustrative incident: latency after a deployment
Symptom: p95 order-write latency rises from 300 ms to 4 s after a release, while throughput and CPU remain stable.
Hypothesis 1: the release introduced slower SQL.
Evidence against slower SQL execution: representative command timings and traces show similar SQL duration, with extra elapsed time before the instrumented command span. Check the instrumentation boundary: connection acquisition may not be included, and a sampled trace alone cannot rule out every SQL regression.
Hypothesis 2: requests are waiting for a database connection.
Evidence: connection-pool usage is pinned at its limit; logs show timeouts acquiring connections; memory and CPU are normal.
Next question: why are connections held longer?
Compare code paths and traces. In this example, an external HTTP call was added after a database transaction opened its connection, extending the connection-holding time; confirm this overlap instead of inferring it only from the deployment time.
Mitigation: roll back or feature-disable the new path. Do not increase the connection pool blindly; that may move saturation to the database.
Permanent fix: avoid holding the database transaction/connection while waiting on the remote call, shorten transaction scope, add acquisition-time measurement and load-test the repaired flow. Preserve business consistency when moving the call: external effects may need idempotency, an outbox or a durable workflow/compensation rather than merely reordering statements.
Safe mitigation hierarchy
- Stop or roll back the suspected triggering change when the evidence and rollback safety support it; consider schema compatibility and irreversible effects.
- Shed optional work and protect critical routes.
- Reduce expensive fan-out, retries, or background concurrency.
- Apply a temporary capacity increase only if the dependency can absorb it.
- Communicate customer impact and recovery criteria.
Every mitigation needs an owner, expiry condition and rollback plan. Capture useful evidence when safe, but do not delay urgent customer-protective action solely to collect diagnostics.
Common interview mistakes
- claiming root cause from temporal correlation alone;
- restarting before capturing useful state;
- increasing timeouts when the dependency is saturated;
- retrying all failures, including permanent or non-idempotent operations;
- averaging latency and hiding tail behavior;
- using trace IDs as metric labels and causing cardinality explosion;
- monitoring queue depth without oldest-item age.
Senior interview questions
- How do you distinguish thread-pool starvation from high CPU?
- Why can p50 stay healthy while customers still report severe slowness?
- Which signals reveal a retry storm?
- What evidence would justify increasing a database connection pool?
- How do you trace a request after it is handed to a background worker?
- Which mitigation would you choose if one tenant causes most saturation?
Practice scenario
A report-export queue grows continuously, consumer CPU is 20%, no errors are logged, and the oldest message is 45 minutes old. Build three competing hypotheses, name one signal that can disprove each, and propose a reversible mitigation. Your answer should discuss downstream throttling, consumer concurrency, poison messages, and deployment changes rather than assuming a single cause.
Review checklist
A strong diagnosis separates symptom, hypothesis, evidence, mitigation, and permanent fix. It also explains what would change your mind.
Check the boundary
Sampled traces show unchanged SQL-command duration after a release, but request latency rose. Which conclusion is supported?
Show answer
Correct answer: D
Command timing has an instrumentation boundary, and samples do not describe every request. Form a falsifiable hypothesis and collect corroborating evidence before changing capacity or declaring cause.
Hint: Ask which part of the request the command span does not cover.
Two-minute interview practice
Attempt both before comparing. State the assumption, the repair and one limit of your evidence.
- The export queue is growing, CPU is 20% and there are no errors. Name three competing explanations and one check for each.
- Why are request IDs useful for investigation but usually poor metric dimensions?
Hint. Revisit the ownership, time, transaction or measurement boundary in the trace table.
Check your reasoning.
- Downstream throttling: inspect response codes/retry waits. Too little effective consumer concurrency: inspect active workers, permit waits and deployment settings. A stuck/poison item or repeated recovery loop: inspect per-item attempt/state transitions and oldest-item age. These are hypotheses, not conclusions from CPU alone.
- They can correlate individual log/trace records, subject to data policy, but unbounded request-ID labels create excessive metric cardinality and cost.
Evidence for the repair
Rehearse the answer as symptom → hypothesis → evidence → reversible mitigation → recovery criterion. Name an observation that would change your mind, and keep the permanent fix separate from the immediate mitigation.
Practice
TechInterviewNotes Editorial Team · Updated 28 Oct 2026 ·