Skip to main content
BLUEPRINT #04Storage & Search

Design a Distributed Metrics Monitoring & Alerting System

Target AWS Architecture:DynamoDBS3SNSKinesis
10-Stage Structure:1. Requirements→2. Sizing→3. Topology→4. Data Model→5. AWS Topology→6. Deep-Dive→7. Failures→8. SRE Playbooks

1. Problem Statement & Scope Clarification

System Mission

Design an ultra-high-throughput, planetary-scale metrics monitoring, time-series storage, and alerting platform (similar to Prometheus/Thanos, Datadog, and Amazon CloudWatch) capable of ingesting tens of millions of metric points per second, executing real-time alert rules with sub-minute evaluation cycles, and delivering sub-second analytical dashboard queries over multi-year time horizons.

Functional Requirements

  1. Metric Ingestion (PushMetric / BatchIngest): Ingest high-throughput, structured time-series metrics (metric_name, timestamp_epoch_sec, value_float64, tags/labels).
  2. Flexible Tag-Based Query Engine: Support multi-dimensional label filtering (e.g., cpu.util{env="prod", region="us-east-1", service="payment"}) and mathematical rollups (avg, sum, rate, ).
  3. Real-Time Alerting Engine: Continuously evaluate user-defined threshold and anomaly rules over sliding windows, dispatching deduplicated alerts to PagerDuty, Slack, and webhooks.
  4. Automated Downsampling & Tiered Retention: Progressively aggregate high-resolution 1-second metrics into 1-minute and 1-hour rollups to optimize storage costs over multi-year retentions.

Non-Functional Requirements (SLAs & SLOs)

  • High Ingestion Throughput: Ingest >10,000,000Β metricΒ points/sec> 10,000,000\text{ metric points/sec} (10MΒ points/sec10\text{M points/sec} sustained, Peak: 30MΒ points/sec30\text{M points/sec}).
  • Query Latency: Dashboard queries for recent data (<2Β hours< 2\text{ hours}): P95<50Β msP95 < 50\text{ ms}; historical range queries (30Β days30\text{ days}): P95<500Β msP95 < 500\text{ ms}.
  • High Availability: 99.999%99.999\% uptime for ingestion and alerting.
  • Compression Efficiency: Achieve β‰₯90%\ge 90\% storage reduction using Gorilla XOR Floating-Point Compression.

2. Capacity & Scale Estimation (Back-of-the-Envelope Math)

Ingestion Scale & Network Bandwidth

  • Sustained Ingest Rate: 10,000,000Β dataΒ points/sec10,000,000\text{ data points/sec} (10MΒ points/sec10\text{M points/sec}).
  • Peak Ingest Rate (3Γ—3\times multiplier): 30,000,000Β points/sec30,000,000\text{ points/sec}.
  • Raw Metric Point Size: 64Β bytes64\text{ bytes} (metric_name pointer, 8B timestamp, 8B float value, label pointers).
  • Peak Raw Ingress Bandwidth: Bandwidth=30Γ—106Β points/secΓ—64Β bytes=1.92Β GB/secβ‰ˆ15.36Β Gbps\text{Bandwidth} = 30 \times 10^6\text{ points/sec} \times 64\text{ bytes} = 1.92\text{ GB/sec} \approx \mathbf{15.36\text{ Gbps}}

Gorilla Compression & Storage Derivations

Using Facebook's Gorilla compression algorithm (Delta-of-delta timestamps + XOR float64 values):

  • Average compressed size per point: β‰ˆ1.37Β bytes\approx 1.37\text{ bytes} (>97%> 97\% reduction).
  • Compressed Daily Ingestion Volume: DailyΒ CompressedΒ Storage=10Γ—106Β points/secΓ—86,400Β secΓ—1.37Β bytesβ‰ˆ1.18Β TB/day\text{Daily Compressed Storage} = 10 \times 10^6\text{ points/sec} \times 86,400\text{ sec} \times 1.37\text{ bytes} \approx \mathbf{1.18\text{ TB/day}}

Tiered Storage Footprint (1-Year Accumulation)

  1. Hot Tier (In-Memory / NVMe SSD - 2 Hours): 10MΒ pts/secΓ—7,200Β secΓ—1.37Β bytesβ‰ˆ98.6Β GBΒ RAM10\text{M pts/sec} \times 7,200\text{ sec} \times 1.37\text{ bytes} \approx \mathbf{98.6\text{ GB RAM}}
  2. Warm Tier ( / Timestream - 30 Days): 1.18Β TB/dayΓ—30Β daysβ‰ˆ35.4Β TB1.18\text{ TB/day} \times 30\text{ days} \approx \mathbf{35.4\text{ TB}}
  3. Cold Tier (Downsampled Parquet Lakehouse - 1 Year): Downsampling raw 1s metrics to 1-minute rollups (60Γ—60\times reduction) + 1-hour rollups (3600Γ—3600\times reduction): AnnualΒ ColdΒ Storageβ‰ˆ1.18Β TB/dayΓ—365Β days60β‰ˆ7.18Β TB/year\text{Annual Cold Storage} \approx \frac{1.18\text{ TB/day} \times 365\text{ days}}{60} \approx \mathbf{7.18\text{ TB/year}}

3. High-Level Architecture & AWS Component Mapping

Interactive Architecture Diagram
Synthesizing vector architecture diagram...

4. Storage Engine Internals: The Gorilla Compression Algorithm

1. Delta-of-Delta Timestamp Encoding

Timestamps typically arrive at fixed intervals (e.g., every 10 seconds: tβˆ’1=10,t0=20,t1=30t_{-1} = 10, t_0 = 20, t_1 = 30).

  • First Delta: D=t1βˆ’t0=10D = t_1 - t_0 = 10
  • Delta-of-Delta: Dβ€²=(t1βˆ’t0)βˆ’(t0βˆ’tβˆ’1)=10βˆ’10=0D' = (t_1 - t_0) - (t_0 - t_{-1}) = 10 - 10 = 0
  • If Dβ€²==0D' == 0, encode as a single bit 0.
  • If βˆ’63≀D′≀64-63 \le D' \le 64, encode as bits '10' + 7 bits of Dβ€²D'.
  • If βˆ’255≀D′≀256-255 \le D' \le 256, encode as bits '110' + 9 bits of Dβ€²D'.
  • Otherwise, store bits '1110' or '1111' with full integer value. Over 95%95\% of points encode into a single 0 bit.

2. XOR Floating-Point Value Compression

Interactive Architecture Diagram
Synthesizing vector architecture diagram...

5. Time-Series Inverted Index & Label Posting Lists

To enable ultra-fast label queries like node.cpu{region="us-east-1", env="prod"}, the TSDB maintains an In-Memory utilizing Roaring Bitmaps:

text
Label Index:
"__name__=node.cpu"  -> RoaringBitmap: [Series 1, Series 4, Series 9, Series 12]
"region=us-east-1"    -> RoaringBitmap: [Series 1, Series 2, Series 4, Series 15]
"env=prod"            -> RoaringBitmap: [Series 1, Series 4, Series 8]

Query: node.cpu AND region=us-east-1 AND env=prod
Result: Bitwise AND Intersection = Series 1, Series 4 (Executed in < 5 microseconds)

Part 2: Production Deep-Dive Locked1 Coin = 24 Hours

Unlock Complete Architecture & Production Runbooks

Your Balance:40 Coins

You have explored the free architectural preview (~45%). Spend 1 Coin to unlock the remaining 6 production deep-dive sections for a full 24 hours.

Sections Included in This 24-Hour Pass:
6. Detailed Alert Evaluation & Notification Workflow
7. Metrics Architecture Trade-Off Matrix
8. Failure Modes, Resiliency & Critical Edge Cases
9. Production Pitfalls & Anti-Patterns (The "Gotchas")
10. Production Runbook & Observability Guide
11. Interview Strategy & System Design Rubric
Keeps page unlocked for exactly 24 hoursSpend coins to fund LLM & compute infrastructure