Design a Distributed Metrics Monitoring & Alerting System
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
- Metric Ingestion (
PushMetric/BatchIngest): Ingest high-throughput, structured time-series metrics (metric_name,timestamp_epoch_sec,value_float64,tags/labels). - 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,p99). - Real-Time Alerting Engine: Continuously evaluate user-defined threshold and anomaly rules over sliding windows, dispatching deduplicated alerts to PagerDuty, Slack, and webhooks.
- 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 ( sustained, Peak: ).
- Query Latency: Dashboard queries for recent data (): ; historical range queries (): .
- High Availability: uptime SLA for ingestion and alerting.
- Compression Efficiency: Achieve storage reduction using Gorilla XOR Floating-Point Compression.
2. Capacity & Scale Estimation (Back-of-the-Envelope Math)
Ingestion Scale & Network Bandwidth
- Sustained Ingest Rate: ().
- Peak Ingest Rate ( multiplier): .
- Raw Metric Point Size: (
metric_namepointer, 8B timestamp, 8B float value, label pointers). - Peak Raw Ingress Bandwidth:
Gorilla Compression & Storage Derivations
Using Facebook's Gorilla compression algorithm (Delta-of-delta timestamps + XOR float64 values):
- Average compressed size per point: ( reduction).
- Compressed Daily Ingestion Volume:
Tiered Storage Footprint (1-Year Accumulation)
- Hot Tier (In-Memory / NVMe SSD - 2 Hours):
- Warm Tier (ClickHouse / Timestream - 30 Days):
- Cold Tier (Downsampled S3 Parquet Lakehouse - 1 Year): Downsampling raw 1s metrics to 1-minute rollups ( reduction) + 1-hour rollups ( reduction):
3. High-Level Architecture & AWS Component Mapping
Interactive Architecture DiagramSynthesizing 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: ).
- First Delta:
- Delta-of-Delta:
- If , encode as a single bit
0. - If , encode as bits
'10'+ 7 bits of . - If , encode as bits
'110'+ 9 bits of . - Otherwise, store bits
'1110'or'1111'with full integer value. Over of points encode into a single0bit.
2. XOR Floating-Point Value Compression
Interactive Architecture DiagramSynthesizing 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 Inverted Index utilizing Roaring Bitmaps:
textLabel 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)
Unlock Complete Architecture & Production Runbooks
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.