Back to sketch

SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 10

Design a metrics aggregation and query system

Advanced · 45 min · Observability

Every service in the company reports numbers such as request counts, queue depths and latency histograms, each tagged with things like service, region and host. Engineers open dashboards that chart these numbers over the last hour or the last year, and they expect a chart to load while they are still looking at it.

Requirements

  • Accept samples for a series identified by a metric name plus a set of tag key/value pairs.
  • Answer range queries that filter by tags, group by tags, and aggregate (sum, rate, max, percentiles) over a time range.
  • Keep recent data at full resolution and older data at coarser resolutions, deleting data past its retention.
  • Stop one team from degrading the system for everyone else.

Constraints and assumptions

  • 50 million active series, each reporting one sample every 10 seconds (about 5 million samples per second, peaks of 2x).
  • A sample is a 64-bit timestamp and a 64-bit float. Series have up to 10 tags.
  • Retention: 10-second data for 15 days, 5-minute rollups for 90 days, 1-hour rollups for 2 years.
  • Dashboard queries over the last 6 hours should return in under 1 second at p95; a 30-day query may take a few seconds.
  • Samples arrive already collected and batched by an upstream pipeline. They can be up to 10 minutes late.

Out of scope for the first sketch

Agents on hosts and the collection transport · Alert rule evaluation and paging · Logs and traces

Draw your design

Rough math and notes

Done on paper? Compare with the worked approaches