Hello! Welcome to your next lesson in the Staff-Level System Design module.
In our last session, we designed a hyperscale distributed job scheduler, tackling complex issues like fault-tolerant execution with fencing tokens and tenant isolation with shuffle sharding. A critical question we touched upon was, "How would we know if this complex system is actually working correctly in production?"
Today, we will answer that question directly. Our learning outcome is to articulate an observability strategy for a distributed system, covering metrics, logging, and tracing.
For a Staff or Senior Staff engineer, it's not enough to simply list these "three pillars." You are expected to articulate a cohesive strategy that explains why each pillar exists, how they interrelate to solve problems, the architectural patterns needed to implement them at scale, and the critical trade-offs involved—especially around cost and performance. This is a core competency for anyone responsible for the operational health of a large-scale service.
1. Observability vs. Monitoring: Answering "Why?"
First, let's establish a precise definition. In interviews, candidates often use "monitoring" and "observability" interchangeably, but at the Staff level, demonstrating a clear understanding of the distinction is crucial.
- Monitoring is about tracking the health of a system against a set of predefined signals (the known unknowns). You know which metrics matter (e.g., CPU usage, error rate), and you create dashboards and alerts to watch them. It answers the question, "What is broken?"
- Observability, on the other hand, is about designing a system to be debuggable for problems you can't predict (the unknown unknowns). It's the ability to ask arbitrary questions about your system's state without having to ship new code to answer them. It answers the question, "Why is it broken?"
Distributed Systems Observability Explained
This article from EdgeDelta provides a concise, clear distinction between monitoring and observability, which is a perfect starting point for our discussion.
Please read the first two sections, 'What Is Distributed Systems Observability?' and 'Why Observability Is Critical for Distributed Systems'. Focus on the table that compares the two concepts and the analogy of a 'fire alarm' versus a 'fire investigation'.
In essence, monitoring tells you that your car's engine temperature is high. Observability gives you the tools (engine diagnostics, fuel pressure readings, coolant levels) to figure out why.
2. The Three Pillars of Observability
Observability is built on three core types of telemetry data: logs, metrics, and traces. Each provides a unique perspective on your system's behavior. A great way to understand their distinct roles and relationships is to see them as different ways of interpreting system events.
dotScale 2017 - Adrian Cole - Observability 3 ways: Logging, Metrics & Tracing
This classic talk by Adrian Cole from dotScale is one of the best explanations of the three pillars. It clearly defines each one and discusses their unique value.
Please watch from the beginning to 06:31. Pay close attention to how the speaker defines each pillar and its primary value proposition: Logs: The focus is on the individual, often stateless, event. Metrics: The focus is on aggregates and trends over time. Traces: The focus is on request-scoped causality, showing the lifecycle of a request.
Let's break down each pillar with more detail.
Pillar 1: Logs (The Detailed Record)
Logs are discrete, timestamped records of events. A log entry provides the most granular, context-rich information about a specific point in time within a single service.
- What it is: A text or structured (e.g., JSON) line describing an event, like
{"timestamp": "...", "level": "error", "service": "auth-service", "trace_id": "abc-123", "msg": "database connection failed"}. - Best for: Answering "Why did this specific thing fail?" during a deep-dive investigation.
- Challenge: High volume, high storage cost, and can be noisy if not structured.
Pillar 2: Metrics (The Aggregated View)
Metrics are numerical measurements aggregated over a time interval. They are the foundation of dashboards and alerts, providing a high-level view of system health.
- What it is: A number with a name and tags (labels), like
http_requests_total{method="POST", path="/api/v1/jobs", status="500"}: 15. - Best for: Answering "Is the system healthy?" by tracking trends (e.g., error rates over time) and setting alerts on SLOs.
- Common Types:
- Counter: A value that only increases (e.g., total requests).
- Gauge: A value that can go up or down (e.g., current active connections).
- Histogram: A distribution of values in configurable buckets (e.g., request latency percentiles like p50, p95, p99).
- Challenge: Loses individual request context. An average latency can hide significant outliers.
Pillar 3: Traces (The Request Journey)
A trace represents the end-to-end journey of a single request as it propagates through multiple services in a distributed system. Each operation within a trace is called a span.
- What it is: A tree of spans, where each span has a start time, duration, and metadata (tags). The
trace_idlinks all spans in a single request together. - Best for: Answering "Where in the system is this request slow or failing?" It's invaluable for pinpointing bottlenecks.
- Challenge: Can be complex to implement (requires context propagation) and expensive to store, often requiring sampling.
The following diagram provides a great visual summary of the three pillars and the kinds of tools used for each.

3. A Practical Workflow: Connecting the Pillars
The true power of observability comes from using the pillars together. In an incident, you'll typically navigate from metrics to traces to logs.
Let's apply this to our distributed job scheduler from the last lesson. Imagine an incident unfolds:
| Signal | Role in Investigation | Insight Gained (Job Scheduler Example) |
|---|---|---|
| Metrics | Detect that something is wrong. | An SLO alert fires: "P99 job scheduling latency for high-priority tenant has breached the 2-second threshold." A Grafana dashboard shows a sharp spike. |
| Traces | Reveal where the failure or slowdown is occurring. | We find a sample trace for a slow job. The trace waterfall view shows that a specific span, acquire-job-lease, within the scheduler-service is taking 1.8s. |
| Logs | Explain why it happened with exact event details. | We pivot to our log system (e.g., Loki or Splunk) and filter for trace_id=<the-slow-trace-id>. We find a log line: level=WARN msg="database connection pool exhausted, waiting for connection". |
Root Cause: A misconfiguration in the scheduler's database connection pool is causing it to starve under load, leading to high scheduling latency for a key tenant. Without all three pillars working together, finding this would be like searching for a needle in a haystack.
4. Architecting an Observability Pipeline
Collecting telemetry from thousands of services and making it queryable is a massive system design problem in itself. A typical pipeline involves several stages.
Distributed Metrics/Logging Design Deep Dive with Google SWE! | Systems Design Interview Question 14
This video from 'Jordan has no life' gives a great walkthrough of designing a distributed metrics and logging system, which is the backbone of an observability platform.
This video covers a lot of ground. Focus on these key architectural decisions: Ingestion (04:42 - 06:39): Why a log-based message broker like Kafka is chosen over an in-memory one for durability and replayability. Stream Processing (06:39 - 10:32): The role of stream processors (like Flink) for real-time aggregation (e.g., creating 1-minute metrics from raw data) and enrichment (adding metadata). Storage (10:32 - 15:16): The different storage solutions for different data types: Time-Series Databases (TSDBs) for metrics, and data lakes (S3) or data warehouses for logs and batch analytics. Overall Architecture (17:39 - 20:02): Watch the final diagram walkthrough to see how all the pieces connect.
The key architectural components are:
- Instrumentation: Your application code is instrumented (ideally using a standard like OpenTelemetry) to emit logs, metrics, and traces.
- Collection & Ingestion: Agents (e.g., OpenTelemetry Collector) on each host or sidecar collect this data and forward it to a central ingestion point. To handle massive volume, this data is typically published to a durable message queue like Apache Kafka or AWS Kinesis.
- Processing: Stream processing systems like Apache Flink or Spark Streaming consume the raw data from Kafka to perform aggregation (e.g., calculating p99 latencies), enrichment (e.g., adding geolocation data to an IP address), and filtering.
- Storage & Querying: The processed data is routed to specialized databases optimized for each data type:
- Metrics -> Time-Series Database (TSDB): Prometheus, Mimir, VictoriaMetrics. Optimized for fast writes and time-based queries.
- Logs -> Log Aggregation/Search System: Elasticsearch, Loki, OpenSearch. Optimized for full-text search.
- Traces -> Tracing Backend: Jaeger, Tempo, Lightstep. Optimized for storing and querying trace structures.
- Visualization: Tools like Grafana query these various backends to build dashboards and power alerts.
5. Staff-Level Trade-offs and Considerations
Discussing the following topics demonstrates the operational maturity and strategic thinking expected at the Staff+ level.
Cardinality and Cost
Cardinality refers to the number of unique values for a metric's labels (tags). This is arguably the biggest challenge in observability at scale.
- Low Cardinality:
http_status_codehas few unique values (200, 404, 503, etc.). This is cheap. - High Cardinality: Adding a
user_idlabel to a metric can create millions or billions of unique time series.requests_total{user_id="1"},requests_total{user_id="2"}, ...
High cardinality explodes storage costs and grinds query performance to a halt. In an interview, stating that you would never use unbounded-cardinality identifiers like user_id or trace_id as metric labels is a huge green flag.
Sampling Strategies for Traces
Storing 100% of traces for a high-traffic service is prohibitively expensive. This is where sampling comes in.
- Head-based Sampling: The decision to keep or drop a trace is made at the beginning of the request (at the first service). It's simple and low-overhead, but you might drop traces that later turn out to be interesting (e.g., an error occurs).
- Tail-based Sampling: The decision is made after the entire trace has completed. This allows you to make intelligent decisions, like "keep 100% of traces with errors" and "sample 1% of successful traces." It's more powerful but requires a more complex collection pipeline that can buffer all spans for a trace before making a decision.
This image perfectly illustrates the difference:

Context Propagation
For tracing to work, the trace_id must be passed between services with every network call. This is called context propagation. Modern frameworks handle this automatically using standard HTTP headers, most notably the W3C Trace Context standard (traceparent header). Mentioning this standard shows you're familiar with modern, interoperable best practices.
Conclusion
Today we've constructed a comprehensive observability strategy suitable for a large-scale distributed system. You can now articulate not just what the three pillars are, but how to design a system to support them and the critical trade-offs you must navigate.
Key Takeaways:
- Observability is for the Unknowns: It's about building systems that are inherently debuggable, answering why things fail, not just what failed.
- Unify the Pillars: The real power lies in correlating metrics, traces, and logs to move from detection to root cause analysis. A
trace_idis the thread that ties them together. - Design for Scale: A real-world observability platform is a massive distributed system in its own right, relying on message queues (Kafka), stream processing (Flink), and specialized databases (TSDBs).
- Master the Trade-offs: For a Staff-level discussion, you must address the hard problems: managing cardinality to control costs, choosing the right sampling strategy for traces, and understanding the cost-benefit of different data retention policies.
Preview of the Next Lesson:
Now that we know how to observe our system and ensure it's operating correctly, we must ensure it's secure. Our next lesson will be: Articulate a security model for a system design, covering authentication, authorization, and data protection.