Observability, Logging & Tracing
Debug distributed latency spikes and failures across 50 services using metrics, logs, and traces.
In plain words
Observability is being able to see what is happening inside your system. Logs say what happened, metrics show how much and how fast, and traces follow one request across services.
Think of it like…
Metrics are the car’s dashboard gauges (speed, engine temp); Traces are the GPS route showing which intersection delayed you; Logs are the dashcam recording.
Where you’ve seen it
When checkout gets slow, a trace shows the request spent 2 seconds waiting on the payment service, which points the team straight to the problem.
Words you’ll hear
- Logs
- Timestamped text records of events.
- Metrics
- Numbers over time, such as requests per second or error rate.
- Distributed trace
- The path and timing of one request through many services.
- p99 latency
- The response time that 99% of requests are faster than.
Visual diagram
Theory & deep dive
Metrics tell you WHAT, Traces tell you WHERE, Logs tell you WHY
When an incident hits at 2 AM, you never want to SSH into 40 servers grepping plain text files. Instead, every request gets a `trace_id` at the API Gateway, propagated through HTTP headers and Kafka messages.
Aggregated Metrics wake you up when error rates or p99 latency cross an SLO. Clicking a slow spike opens a Distributed Trace waterfall showing exactly which microservice/SQL query burned 2 seconds, and filtering Structured JSON Logs by that trace_id reveals the exact error stack and context.
trace_id everywhere, watch RED metrics (Rate, Errors, Duration), and avoid high-cardinality metric labels.How it works, step by step
Step 1 of 41. Emit RED / USE Metrics into a TSDB
Track Rate, Errors, and Duration (histograms for P50/P95/P99) scraped or pushed into a Time-Series DB (Prometheus, VictoriaMetrics). Keep label cardinality bounded!
- Key Percentiles
- P50, P95, P99
- Watch Out
- Label cardinality
When to use it & trade-offs
What it is
Observability rests on three pillars: Metrics (numeric time-series aggregations), Logs (structured event records), and Distributed Traces (end-to-end request spans linked by a trace ID).
Why it matters: When a user reports “checkout took 9 seconds”, console.log on 40 isolated hosts is useless unless you can correlate spans, P99 histograms, and logs.
When to reach for it
- Monitoring P99 latency (not just averages, which hide slow tails)
- Propagating
trace_idacross both HTTP/gRPC headers and Kafka message headers - Downsampling older TSDB metrics (10s → 5m → 1h) for cheap multi-year dashboards
When to avoid or be careful
- Putting unbounded IDs (
request_id,email,url) as Prometheus metric tags (cardinality explosion) - Logging synchronously over the network inside the request hot path
The Three Pillars of Observability
Strengths: Tiny storage cost, fast range queries, ideal for real-time alerting.
Watch out: Cannot store high-cardinality IDs (user_id, order_id) without blowing up RAM.
Strengths: Rich arbitrary context per event when filtered by trace_id.
Watch out: Expensive at petabyte scale unless sampled, compressed, and retention-tiered.
Strengths: Visualizes exact parent-child timing across async and sync hops.
Watch out: High volume at 100k QPS requires smart head or tail sampling.
Interview signals & numbers to know
When this topic comes up
- debug latency
- metrics & alerting
- centralized logging
- trace spans
- cardinality
Benchmarks & rules of thumb
- Trace sampling (healthy)
- 1–5%
- Error / slow trace capture
- 100% (tail-sampled)
- Metrics scrape interval
- 10–30s
- Hot log retention
- 7–30 days (cold in S3)
Common mistakes & follow-ups
Common interview mistakes
- Monitoring only average latency (an average of 50 ms can hide 5% of users waiting 4 seconds!)
- Creating high-cardinality metric labels (
path=/users/12345), crashing the TSDB - Forgetting to scrub bearer tokens, credit cards, and passwords from log pipelines
Likely interviewer follow-ups
- Why does high label cardinality crash time-series databases like Prometheus?
- Compare head-based vs. tail-based trace sampling - which catches rare errors better?
- Why is P99 latency much more informative than mean latency?
trace_id propagation, P99 histograms, tail-based sampling for errors, and avoiding high-cardinality metric labels.Knowledge check
Put it into practice
Design full architectures with AI feedback
Apply Observability, Logging & Tracing inside real High-Level Design prompts or review Q&A flashcards.