Explore / Backend system design
Design a Metrics Monitoring and Alerting System
Overview
Design the monitoring platform a large company uses to watch its own infrastructure and services. Every host, container and service emits numeric metrics (CPU use, request rate, error count, latency percentiles, queue depth). Engineers look at them on dashboards, and alert rules page the on-call engineer when, for example, the error rate of checkout goes above 2% for five minutes.
The question has three hard parts. Writes dominate: millions of tiny samples arrive every second and must never back up. Storage must be cheap enough to keep months of data, which needs a purpose-built time series format, not rows in a general database. And alerting must keep working when everything else is on fire, because the monitoring system is most needed exactly when the infrastructure is failing. Write your answer in the Write tab and sketch the architecture in the Diagram tab.
Requirements
Functional
- Collect metrics from hosts, containers and services: counters, gauges and histograms, each identified by a name and labels such as
service,region,status. - Query with filters and aggregations (sum, rate, percentiles) over a time range, for dashboards and ad-hoc debugging.
- Define alert rules on queries, with thresholds and durations, and route alerts to on-call tools (PagerDuty, Slack, email).
- Keep high-resolution recent data and lower-resolution history.
Non-functional
- Ingest never blocks the services being monitored and keeps up with bursts.
- Fresh data: a sample is queryable within about 10–30 seconds.
- Fast queries: dashboards over the last hour load in under a second.
- Alerting is the most available part: it keeps evaluating during partial outages and never sends the same page 50 times.
- Cost: months of data for a large fleet at a reasonable storage bill.
- Losing an occasional sample is acceptable. Losing alerting is not.
Estimates
Assume 100,000 hosts, each exposing about 1,000 active time series (one series = one metric name + one combination of label values), collected every 10 seconds. Keep raw data for 30 days and hourly rollups for 2 years, with 3 replicas. Work out:
- Active series and samples per second.
- Raw storage per day uncompressed (a sample is a 64-bit timestamp and a 64-bit value) and with time series compression.
- What the 2-year history costs with and without downsampling.
- How many alert-rule queries per second you run if there are 50,000 rules evaluated every 30 seconds.
Hints
- Who starts the conversation: does each server push its metrics, or does the platform pull them? What does each choice tell you when a server dies?
- Consecutive samples of one series are very similar, and timestamps arrive at almost fixed intervals. How can you exploit that?
- A developer adds
user_idas a label. What happens to the number of series? - Nobody needs 10-second resolution for last year's data. What do you keep instead?
- If alert rules run against the same storage that is overloaded during an incident, what happens to the pages?
Follow-ups
- How do you know the monitoring system itself is working?
- How would you support a percentile like p99 latency across 500 servers?
- A team's deploy creates 20 million new series in ten minutes. What protects everyone else?
- How would you support logs and traces as well? What changes?
- How would you build this as a multi-tenant SaaS product?
Write your answer step by step and compare it with the reference solution on GrindPrep.