Design a metrics monitoring and alerting system like Datadog or Prometheus
Role: Software Engineer
Category: System Design
Difficulty: hard
Interview Round: Other
Design a metrics monitoring and alerting system similar to Datadog or Prometheus. Users collect metrics from their infrastructure and applications, look at them on dashboards, and get alerted when the real-time operational health of a system degrades.
The system must:
1. Ingest infrastructure and application metrics (for example CPU usage) paired with tags or labels such as `env:prod`.
2. Let users build dashboards that query, aggregate and visualize metrics over arbitrary time ranges.
3. Let users configure threshold alerts, for example `Alert if CPU > 90% for 5 minutes`.
4. Send alerts to external channels such as PagerDuty, Slack and email.
Before drawing the architecture, state the non-functional requirements you are designing for: availability, alert latency, dashboard latency, retention and storage cost.
```hint Start from the numbers
Convert the ingest rate into active series and bytes per day before choosing storage. Those numbers tell you how much compression and downsampling you need.
```
```hint Where rules run
Estimate the read load if every alert rule queried storage on each evaluation, and ask whether rules have to read from storage at all.
```
```hint Count the series
A series is a metric name plus one combination of tag values. Ask what a single tag with a unique value per request does to the number of series.
```
### Constraints & Assumptions
- Plan for at least 10 million data points per second across all customers.
- The platform is multi-tenant: many customer organizations share it.
- On the ingestion path, availability matters more than consistency.
### Clarifying Questions to Ask
- Do agents push metrics to the service, or does the service scrape endpoints on customer hosts?
- How long must data be kept, and at what resolution once it is old?
- Does `CPU > 90% for 5 minutes` mean the 5-minute average is above 90%, or that every reading in those 5 minutes is above 90%? Is it evaluated per host or across the fleet?
- How late can data arrive, and should a series that stops reporting raise an alert?
- How much delay is acceptable between a threshold breach and the page?
### What a Strong Answer Covers
- Non-functional targets with numbers, plus an estimate of active series and storage per day that drives the storage choice.
- How raw points are stored and compressed so writes keep up with ingest and storage stays affordable.
- How rules are evaluated within seconds without loading the storage layer, including rule updates, late data and duplicate notifications.
- How data is downsampled and retained, and how a query over several months stays fast.
- How data is sharded, and how the system contains a tenant whose tags cause a cardinality explosion.
### Follow-up Questions
- How would you alert when a host stops sending metrics altogether?
- A metric hovers around its threshold, and the alert fires and resolves every minute. How do you stop the flapping?
- How would you show a correct p99 request latency across 500 hosts on one chart?
- How would you run this in several regions so that losing one region does not stop alerting in the others?
Overview: Design a metrics monitoring and alerting system that ingests tagged infrastructure and application metrics at millions of points per second, serves dashboards over any time range, and sends alerts to on-call channels. It tests time-series storage and compression, real-time rule evaluation, downsampling and retention, and cardinality control.