System Design: Monitoring, Logging, and Observability

Master the Three Pillars of Observability (Metrics, Logs, Traces), centralized ELK logging, distributed tracing with OpenTelemetry, Prometheus & Grafana, SRE alerting, health probes, and APM.

1. Metrics, Logs, and Traces (The Three Pillars)

While traditional monitoring informs operators when a system is failing (black-box symptom detection), modern observability allows engineers to infer the internal state of complex distributed microservices based on external outputs (white-box debugging).

The Three Pillars of Observability Architecture Comparison

System Design

Contrasting numerical time-series metrics, structured event logs, and distributed request traces

100%
Loading system design canvas…

1. Metrics (Time-Series)

Aggregable numerical data points measured over time intervals. Low storage overhead.

  • Counters: Monotonically increasing values (total requests)
  • Gauges: Fluctuating values (CPU %, memory usage)
  • Histograms: Distribution buckets for calculating p95/p99 latency

2. Logs (Structured Events)

Discrete timestamped JSON records emitted during execution. Provides rich context.

  • Contextual metadata: user_id, order_id, IP address
  • Error stack traces & debug event trails
  • High storage cost; requires index tiering & retention

3. Traces (Request Journeys)

Tracks the lifecycle of a request as it traverses across multiple microservices.

  • TraceID: Unique ID representing the end-to-end request
  • SpanID: Segment representing a specific unit of work (RPC, SQL query)
  • Context Propagation: Passed via HTTP/gRPC headers

2. Centralized Logging Architecture (ELK Stack & Streaming Pipelines)

In high-scale microservice architectures running hundreds of ephemeral container pods, logging to local disk files is impossible to debug. Centralized logging streams, buffers, transforms, and indexes logs into full-text search clusters.

Enterprise Centralized Logging Pipeline (Fluentbit, Kafka, Logstash & Elasticsearch)

System Design

Buffering peak log spikes with Apache Kafka and indexing JSON inverted search indices for Kibana querying

100%
Rendering diagram…

Log Ingestion & Buffering

Protecting storage engines from volume spikes.

  • DaemonSet Log Shippers: Lightweight agents (Fluentbit, Vector) ship pod stdout streams
  • Kafka Buffer: Decouples log producers from slower Elasticsearch indexing writes to prevent log loss during traffic spikes

Transformation & Index Lifecycle (ILM)

Managing storage costs across time.

  • Structured JSON: Always emit structured JSON; avoid raw text strings
  • Hot Tier (NVMe SSD): Active indexing & search (0-7 days)
  • Warm/Cold Tier (HDD / S3 Object Storage): Read-only archived logs (8-90 days)

Production Structured JSON Logger with OpenTelemetry Trace ID Correlation

A structured JSON logger that attaches OpenTelemetry trace IDs so logs can be correlated across services.

3. Distributed Tracing (OpenTelemetry, Jaeger & W3C Trace Context)

When an API request hops across 10 microservices and takes 2 seconds, distributed tracing pinpoint exactly which microservice, database query, or downstream RPC caused the latency bottleneck.

Distributed Request Trace Sequence & W3C Context Propagation

System Design

Tracing TraceID and SpanID hierarchy from API Gateway to slow PostgreSQL database queries

100%
Rendering diagram…

W3C Trace Context Standard

Cross-language context header format: traceparent: 00-{traceId}-{spanId}-{flags}.

  • Trace ID: 16-byte random hex string shared across all child spans in the request
  • Span ID: 8-byte unique identifier for the specific operation
  • Baggage: Key-value metadata propagated across process boundaries (e.g. tenant_id)

Sampling Strategies (Head vs Tail)

Controlling storage and network overhead.

  • Head-Based Sampling: API Gateway samples a fixed % of traces (e.g. 5%) at request start
  • Tail-Based Sampling: Collector buffers all spans in memory and retains 100% of traces that error (5xx) or exceed latency thresholds (>500ms)

4. Monitoring Architecture (Prometheus Pull Scraping & Grafana)

Prometheus has become the cloud-native standard for metrics monitoring. It employs an active pull model where the server periodically scrapes registered HTTP endpoints.

Prometheus Metrics Pull Architecture & Grafana TSDB Topology

System Design

Dynamic Kubernetes service discovery, time-series storage (TSDB), PromQL queries, and Alertmanager routing

100%
Loading system design canvas…

Prometheus Pull Model Advantages

Why pull architecture scales well in container clusters.

  • Automatic Health Detection: If a scrape fails, Prometheus immediately knows the target is down
  • Prevents Overload: Prometheus controls scrape rates; target services never get overwhelmed pushing telemetry
  • Service Discovery: Automatically tracks pods as K8s auto-scales replicas up and down

PromQL (Prometheus Query Language)

Powerful expressions for calculating percentiles.

  • Rate calculation: rate(http_requests_total[5m])
  • p99 Latency: histogram_quantile(0.99, sum(rate(http_request_duration_seconds_bucket[5m])) by (le))
  • Error %: sum(rate(http_requests_total{status=~"5.."}[5m])) / sum(rate(http_requests_total[5m]))

5. SRE Alerting Systems & Preventing Alert Fatigue

Poorly tuned alerting causes Alert Fatigue where engineers ignore pages. Effective SRE alerts trigger exclusively on user-impacting symptoms and Service Level Objective (SLO) burn rates.

SRE Alerting & Incident Escalation Workflow

System Design

Symptom-based evaluation, alert deduplication, inhibition trees, and severity tier routing

100%
Rendering diagram…

SRE Alerting Principles (Google SRE Book)

Design alerts that are actionable, urgent, and symptom-oriented.

  • Alert on Symptoms, Not Causes: Page on high 5xx error rate or elevated user latency, NOT on single CPU blips or memory thresholds
  • Multi-Window Multi-Burn-Rate Alerts: Detect rapid budget burns (14x burn rate over 1h) and slow budget drains (2x burn rate over 6h)
  • Alert Inhibition: If an entire Data Center switch goes offline, suppress individual pod unreachable alerts to avoid 500 duplicate pages

6. Health Check Endpoints: Liveness vs Readiness Probes

Container orchestrators like Kubernetes use dedicated probe endpoints to decide whether to restart an unresponsive container or temporarily remove it from load balancer routing.

Liveness vs Readiness Probe Load Balancer & Container Lifecycle Decisions

System Design

Contrasting container restart triggers against traffic routing removal

100%
Loading system design canvas…

Liveness Probe (/health/live)

Determines if the application process is alive or deadlocked.

  • Action on failure: Kills container and initiates container restart
  • Never check downstream DBs in liveness probes (prevents cascading crash loops!)
  • Execution frequency: Every 10-30 seconds

Readiness Probe (/health/ready)

Determines if the pod is ready to accept user traffic.

  • Action on failure: Removes pod from Load Balancer endpoint list (Pod is NOT killed)
  • Checks database connectivity, warm caches, and memory readiness
  • Allows pods to gracefully recover during heavy traffic spikes

Express.js Prometheus Metrics Collector with Custom Histograms & Health Probes

An Express.js middleware that records custom Prometheus histograms and exposes health-probe endpoints.

7. Application Performance Monitoring (APM) & Continuous Profiling

APM tools (Datadog, Dynatrace, New Relic) automatically instrument runtime bytecode to generate CPU flame graphs, memory allocation profiles, and automated slow query detection without code changes.

APM Full-Stack Continuous Profiling & Flame Graph Analysis

System Design

Continuous thread profiling, heap leak detection, and automated slow database query diagnosis

100%
Rendering diagram…

Key APM Capabilities in System Design

Deep runtime visibility inside application runtimes.

  • Flame Graphs: Visual representation of CPU time spent per function call stack
  • N+1 Database Query Detection: Flags microservices issuing hundreds of repetitive sequential SQL SELECT queries
  • Garbage Collection (GC) Pauses: Highlights JVM / V8 stop-the-world latency spikes in memory-intensive workloads

Knowledge Check

1. What is the primary function of Distributed Tracing in microservices?

2. What architectural model does Prometheus use to gather metrics from services?

3. What action does Kubernetes take when a container fails its Liveness Probe?

4. What is the difference between a Readiness Probe and a Liveness Probe?

5. Why should SRE alerting rules focus on symptom metrics rather than cause metrics?