Interview's MateSystem Design
Interview's Mate

System Design

Architecture & trade-offs

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
System Design topics
Lesson 27/ 31
Reliability, Security & Case Studies

Observability, Logging & Tracing

Debug distributed latency spikes and failures across 50 services using metrics, logs, and traces.

IntermediateMetrics · Logs · Traces3 quiz questions0/2 subtopics done
Practice in AI HLD
In plain wordsDiagramTheorySubtopics (2)Step by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice
Deep-dive subtopics (2) - 0/2 completed
Metrics, Logs & Distributed Tracing

Combine Prometheus metrics, structured JSON logs, and OpenTelemetry trace spans.

Beginner
Actionable Alerting & Trace Sampling

Page engineers only on real user symptoms and keep trace storage bills under control.

Intermediate

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

Loading interactive diagram
Loading interactive exercise

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.

Key takeaway: Propagate a trace_id everywhere, watch RED metrics (Rate, Errors, Duration), and avoid high-cardinality metric labels.

How it works, step by step

Step 1 of 4
Metrics Pipeline

1. 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!

Never put user_id or request_id as a metric label
Key numbers at this step
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_id across 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

Metrics (Prometheus / TSDB)
Best for: Dashboards, P99 latency alerts, CPU/queue-depth auto-scaling

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.

Structured Logs (ELK / Loki)
Best for: Detailed error payloads, audit trails, specific request debugging

Strengths: Rich arbitrary context per event when filtered by trace_id.

Watch out: Expensive at petabyte scale unless sampled, compressed, and retention-tiered.

Distributed Traces (OpenTelemetry / Jaeger)
Best for: Pinpointing N+1 queries and latency waterfalls across microservices

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?
Interview tip: Mention OpenTelemetry trace_id propagation, P99 histograms, tail-based sampling for errors, and avoiding high-cardinality metric labels.

Knowledge check

Loading quiz

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.

Open AI HLD Practice →SD Interview Q&A
Previous topic
Rate Limiting & Throttling
Next topic
Security, Auth & Payment Systems