Quick revision
The short answer
A series is a metric name plus a set of labels such as service, instance, region and endpoint, holding samples of timestamp and value; 20,000 hosts with 2,000 series each make 40 million active series and about 2.7 million samples per second. Collection scrapes /metrics endpoints found through service discovery, with agents and OpenTelemetry collectors for pushed data, storage is a time-series database with an in-memory head block and write-ahead log, compressed blocks, a label index and downsampled copies, and the query API offers range queries with rate, sums by label and histogram quantiles for dashboards and an alert rule evaluator.
What to remember
In this answer, we modelled metrics as series identified by a name and labels, holding timestamped samples, with counters, gauges and histograms as the main types. We sized the load at 40 million series and about 2.7 million samples per second, collected by scraping discovered targets and accepting pushes from agents and OpenTelemetry collectors, stored in a time-series database with a head block, a WAL, compressed blocks, a label index and downsampled copies, and queried with rate, aggregation and histogram quantiles by dashboards and an alert evaluator feeding an alert manager.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A series is a metric name plus a set of labels such as service, instance, region and endpoint, holding samples of timestamp and value; 20,000 hosts with 2,000 series each make 40 million active series and about 2.7 million samples per second. Collection scrapes /metrics endpoints found through service discovery, with agents and OpenTelemetry collectors for pushed data, storage is a time-series database with an in-memory head block and write-ahead log, compressed blocks, a label index and downsampled copies, and the query API offers range queries with rate, sums by label and histogram quantiles for dashboards and an alert rule evaluator.
Why this question is asked
Every production system eventually needs to answer 'is it healthy right now, and how did it behave yesterday?', and the metrics system is where those answers come from. It is also a surprisingly demanding data system: millions of tiny writes per second, nearly all of them appended, and queries that read huge time ranges but return a few lines on a chart. Interviewers ask this design because it tests data modelling, capacity estimates and storage choices together. In this answer, we will define the data model, size the load, design collection, look inside the storage engine, design the query and alerting path, and see how it scales out.
1The Data Model: Series, Labels and Samples
A metric is a named measurement, such as http_requests_total. Labels are key-value pairs that say which instance of it we mean: service, instance, region, endpoint, status. Each unique combination of name and label values is a series, and a series holds samples, pairs of timestamp and value. So http_requests_total{service="cart", endpoint="/checkout", status="500"} is one series, and its samples are a growing list of (time, count) pairs.
There are three main metric types. A counter only goes up, such as total requests, and we look at its rate of increase. A gauge goes up and down, such as memory in use or queue length. A histogram counts observations into buckets, such as how many requests took under 50 ms, under 100 ms and so on, which lets us estimate percentiles later.
Notice that the value is just a number. All the meaning sits in the name and labels, which is why label design decides both how useful and how expensive the system is.
2Sizing the Load
Now the numbers. 20,000 hosts times 2,000 series each is 40 million active series. With one sample per series every 15 seconds, we ingest 40,000,000 / 15, about 2.7 million samples per second.
Storage looks scary until we remember compression. Time-series databases encode timestamps as differences of differences and values with XOR against the previous value, which brings a typical sample to around 1.3 to 2 bytes. At 2 bytes, 2.7 million samples per second is about 5.4 MB per second, roughly 470 GB per day before replication. Memory is the tighter limit: the most recent data for each active series is kept in memory, often a few kilobytes per series, so 40 million series need on the order of 100 to 200 GB of RAM spread over many ingesters. That is why we will shard.
3Collection: Pull and Push
There are two ways to get samples. In the pull model, collectors scrape each target's /metrics endpoint every 15 seconds. Targets are found through service discovery, for example from Kubernetes or Consul, so new pods are picked up automatically. Pull has a useful side effect: if a scrape fails, we know the target is down, and the up metric for it becomes 0.
Pull does not suit everything. A batch job that runs for 20 seconds may finish before anyone scrapes it, and some networks do not allow inbound connections. For those, agents or OpenTelemetry collectors receive pushed metrics, batch them and forward them. In practice, a node agent often scrapes local targets and pushes batches to the central cluster, which combines the benefits of both.
- Targetsservices and hosts expose /metrics; jobs push via OTLP
- Agents and collectorsscrape every 15 s, batch, forward with remote write
- Distributorshash series to ingesters, replicate x3
- Ingestershead block in memory + WAL, cut 2-hour blocks
- Object storagecompressed blocks, label index, downsampled copies
- Queriers and rule evaluatordashboards, alerts -> alert manager
6 layers, from the top down. Step through them one at a time.
4Inside the Storage Engine
A time-series database is built around how metrics arrive: every series gets one new sample at a time, always at the end. The newest data lives in an in-memory head block, typically covering the last two hours. Every sample is also appended to a write-ahead log (WAL) on disk before it is acknowledged, so that a restart can replay the WAL and rebuild the head block without losing data.
Every two hours, the head block is cut into an immutable, compressed block on disk, later compacted into larger blocks and uploaded to object storage such as S3. Each block has an inverted index from label pairs to series, like a search engine's index: service="cart" points to the list of series that carry that label, so a query for one service touches only those series. For long retention, a compactor writes downsampled copies, for example 5-minute and 1-hour averages and maxima, because a year-long chart does not need 15-second resolution.
5The Query API and Alerting
Queries ask for a range of time and an expression. A counter is useless as a raw number, so we apply rate, which computes the per-second increase over a window and handles counter resets after restarts. Then we aggregate by label and, for histograms, estimate quantiles from the buckets.
Dashboards issue these as range queries, GET /api/v1/query_range with the expression, start, end and step. The rule evaluator runs the alert expressions on a schedule; when an expression stays true for the for duration, it sends a firing alert to an alert manager, which groups related alerts, applies silences during maintenance and routes each alert to the right team's pager or chat channel.
6Scaling Out
One server cannot hold 40 million series in memory, so the write path is sharded. Distributors hash each series by its name and labels to choose ingesters, and write each series to three of them for redundancy. Queriers fan a query out to the ingesters for recent data and to the stored blocks for older data, then merge the results. Open-source systems such as Grafana Mimir, Thanos and VictoriaMetrics implement this architecture around the Prometheus data model, so in a real company we would usually run one of them rather than build it.
7Follow-up questions
Pull or push: which would you choose?
Pull for long-running services, because service discovery tells us what should exist and a failed scrape is itself a signal. Push for short-lived jobs and for networks where the collector cannot reach targets. Most real systems use both, often through a local agent that scrapes and then pushes to the central cluster.
Why not store metrics in a general database like PostgreSQL?
At 2.7 million samples per second, a row per sample with indexes would be far too slow and large. Time-series databases compress samples to about two bytes, append without random index updates, and organise data by time blocks so old data can be downsampled and dropped cheaply. PostgreSQL with a time-series extension works for smaller loads, not this one.
How long should we keep raw samples?
A common pattern is 15-second resolution for two to four weeks, 5-minute downsampled data for a few months, and 1-hour data for a year or more. The right values come from what people actually query: incident debugging needs detail for days, capacity planning needs trends for a year.
8Conclusion
In this answer, we modelled metrics as series identified by a name and labels, holding timestamped samples, with counters, gauges and histograms as the main types. We sized the load at 40 million series and about 2.7 million samples per second, collected by scraping discovered targets and accepting pushes from agents and OpenTelemetry collectors, stored in a time-series database with a head block, a WAL, compressed blocks, a label index and downsampled copies, and queried with rate, aggregation and histogram quantiles by dashboards and an alert evaluator feeding an alert manager.
Open with
A series is a metric name plus labels like service, instance, region and endpoint, and it holds samples of a timestamp and a value. The main types are counters, which only go up and are read as a rate, gauges, which go up and down, and histograms, which count observations into buckets so we can estimate percentiles.
Then, if they want more
Twenty thousand hosts times two thousand series is forty million active series, and one sample every fifteen seconds is about 2.7 million samples per second. With delta and XOR compression at around two bytes per sample, that is under half a terabyte a day, and memory for the head data is the real constraint, so ingestion is sharded.
For collection, I would pull by scraping /metrics endpoints found through service discovery, which also tells us when a target is down, and accept pushes through agents and OpenTelemetry collectors for short-lived jobs.
Storage is a time-series database: an in-memory head block with a write-ahead log, two-hour compressed blocks moved to object storage, an inverted index from labels to series, and downsampled copies for long retention. Distributors hash series across ingesters with three replicas.
The query API supports range queries with rate over counters, sums by label and histogram_quantile, used by dashboards and by a rule evaluator that sends firing alerts to an alert manager for grouping, silencing and routing. In practice I would run Mimir, Thanos or VictoriaMetrics rather than build this.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Design the data model, collection path, storage and query API of a metrics system for...": https://scrivio-interview-library.netlify.app/architecture/system-design-problems/9073c7d7e0/