Collect operational metrics from thousands of services and support fast dashboards and alerts.
Control cardinality, distinguish event time from arrival time, and preserve meaning through aggregation.
01. Define the metric types and query needs
A counter accumulates events, a gauge represents a measured value, and a histogram summarizes a distribution. The ingestion API should include metric name, labels, timestamp, value or buckets, and schema version. Queries usually aggregate over time windows and service dimensions.
Decide retention and resolution tiers before choosing storage. A year of raw high-frequency samples may be unnecessary, while a few hours of fine detail can be crucial for incidents. Downsampling must preserve the statistics required by later queries.
02. Calculate cardinality explicitly
A metric with 100 services, ten regions, and five status classes can produce up to 5,000 series if all combinations occur. Adding one million user IDs can multiply the theoretical combinations dramatically. High-cardinality labels create index and memory costs even when individual samples are tiny.
Use bounded labels, per-tenant quotas, and rejection or quarantine for unexpected dimensions. At one million samples per second and an illustrative 16 bytes of raw payload, ingestion is 16 MB per second, or about 1.38 TB per day before labels, indexes, replicas, and compression.
03. Handle duplicates and late samples
Agents batch samples into an ingest tier, which validates and appends to a durable log. Consumers partition by series and write time-oriented storage. Retries require a declared duplicate policy: an identical gauge sample might overwrite by timestamp, while duplicating a delta counter would inflate counts.
Keep event time and arrival time separate. Late data may revise recent windows; very late data can be stored for analysis without retroactively paging an operator. Counter resets and out-of-order points need explicit handling when computing rates.
04. Aggregate without inventing statistics
Averaging p99 values from several servers does not produce the p99 of their combined traffic. Preserve mergeable histogram buckets or another suitable distribution summary. Weight averages by their counts when combining groups with different traffic volumes.
Follow-up: the monitoring pipeline itself fails. Use independent health signals, ingestion-lag alerts, and a clear distinction between no data and a healthy zero. Dashboard availability alone is not evidence that the data is current. Protect alert evaluation from expensive ad hoc queries with separate resource budgets.
Practice the follow-up
Explain why averaging two p99 latency values cannot recover the overall p99, even when the servers have equal request counts.
Connect this to anomaly detection.
Sources & further reading
Prometheus: metric types; Google SRE: monitoring. The interview scenario, calculations, and proposed design choices are illustrative.
Continue your preparation
Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.