Design an internal monitoring system in the style of Prometheus or Datadog. An agent on each of 100,000 hosts reports about 500 metrics (CPU, memory, request rates, custom application counters) every 20 seconds. Engineers build dashboards that query the last hour to the last year, and define alert rules such as 'p99 latency above 500 ms for 5 minutes' that must page the on-call engineer within a minute. The system must stay up during incidents, which is exactly when it is busiest.
Functional requirements
Ingest metrics with names and labels (host, service, region) from agents
Query and graph metrics over time ranges with aggregations (sum, rate, percentiles)
Define alert rules and notify on-call engineers through a paging provider
Keep full-resolution data for 15 days and downsampled data for a year
Non-functional requirements
Alerts fire within 60 seconds of the condition becoming true
Dashboards for the last hour load in under 2 seconds
Ingestion keeps up during incidents when metric volume and dashboard use both spike
Constraints and scale
100,000 hosts x 500 metrics every 20 seconds: 2.5 million samples per second
Agents batch samples into about 5,000 requests per second
50 million active time series; label combinations must be kept bounded
You will practise
Choose a time-series database and understand compression of timestamp and value pairs
Separate ingestion, storage, querying and alerting so each scales on its own
Use downsampling and retention tiers to control storage cost
Show 3 hints
2.5 million samples per second is a lot of rows for a general-purpose database. What makes time-series stores different?
Should alert evaluation read from the same store that dashboards query, or from the incoming stream?
What happens to the number of series if someone adds a user ID label?