The interview problem

Practice prompt

Design retention for one million metric series sampled every ten seconds. Keep raw samples for seven days, one-minute summaries through day 30 and hourly summaries through day 365. Support averages, peaks and latency percentiles. Handle late samples without double counting and explain which historical questions become impossible after deletion.

Original system-design practice, not a reported interview. Workload and storage sizes are hypothetical. Technical reference retrieved September 27, 2026.

1. Make the metric type part of the schema

Distinguish gauges, cumulative counters and distributions. A gauge describes a value at a moment; a counter accumulates events and may reset; a histogram summarizes observations. Applying the same averaging rule to all three produces plausible but incorrect charts.

Define bucket intervals as half-open UTC ranges, such as [12:00, 12:01), and document how boundary timestamps are assigned. Store metric identity, labels, units, type and aggregation schema version. Missing samples are not zero measurements.

For gauges, choose sample-weighted or time-weighted averages explicitly. Uneven sampling makes them different. A time-weighted estimate requires a defined interpolation rule and coverage duration, while a sample mean only needs sum and count. Never label an interpolated estimate as an exact observed value.

2. Keep mergeable summaries

For sample-weighted gauge averages, store sum and count, alongside minimum, maximum and first/last timestamps where useful. An hourly summary merges minute sums and counts; it does not average minute means without their weights.

As a separate irregular-sampling example, suppose one minute has 60 samples averaging 10 and another has six samples averaging 100. The pooled mean is (60 × 10 + 6 × 100) / 66 ≈ 18.18. The unweighted average of the two means is 55. The latter gives the sparse minute as much influence as the dense one.

Minima and maxima preserve extremes across aligned buckets but lose their internal chronology unless additional timestamps are retained. A one-hour maximum cannot tell you whether an overload lasted one second or 59 minutes. Decide whether duration-above-threshold summaries are needed before deleting the raw observations.

3. Do not average percentiles

A percentile is not generally mergeable from percentile values alone. Use compatible histogram bucket counts or an explicitly chosen mergeable sketch to retain distribution information. For cumulative histogram counters, first derive reset-aware interval counts; summing cumulative snapshots across time double-counts earlier observations. Record resolution and approximation guarantees. Different bucket layouts need a supported conversion or coarsening policy; adding unrelated bucket indices is invalid.

Consider two windows using nearest-rank p95. Window A contains 100 observations, all 1 ms; window B contains one observation at 100 ms. Their p95 values are 1 and 100 ms. Averaging gives 50.5 ms, but the combined set has 101 observations and its 96th sorted value is 1 ms, so its p95 is 1 ms.

Even weighting the two percentile values by counts does not recover the combined quantile. A histogram narrows the answer to a bucket and may interpolate under a stated assumption; it does not reconstruct exact raw latencies. If an exact SLO threshold matters, include that boundary or retain a dedicated threshold count.

4. Preserve counter changes before losing resets

For counters, compute reset-aware changes from ordered samples before reducing resolution. A sequence 100, 120, 5, 15 contains a reset. Under the simplifying convention that the post-reset counter began at zero, observed increments are 20 + 5 + 10 = 35. Keeping only first and last values gives −85 and loses the event history.

This estimate cannot reveal increments after 120 but before an unobserved reset. Multiple resets between scrapes may be invisible. Preserve reset markers and coverage information, and describe the measurement limitation instead of claiming exact event counts from intermittent samples.

A bucket's first counter sample may need the preceding sample to calculate its initial delta. Define ownership of cross-boundary increments once so adjacent buckets neither omit nor double-count them. Keep the boundary state needed by the next compaction stage.

5. Publish versioned compactions

Use ingestion storage and a durable change log, followed by minute and hour compaction workers. Each worker reads a defined source snapshot and writes immutable summary blocks. A metadata transaction selects the accepted block revision for each series/time range and records its source revisions.

Queries read a consistent metadata view and choose one representation for each covered interval. Do not sum overlapping raw and minute data for the same time span. Atomically selecting revisions also keeps two retries of the same compaction from both contributing.

Retain source data until the target block is validated, published and recoverable. Verify coverage, checksums and aggregate counts before deleting old raw blocks. Retention is a lifecycle transition with dependencies, not an independent timer that can remove input while a failed compactor is still behind.

6. Treat lateness as a revision

Suppose a late sample arrives for a minute already summarized. Deduplicate by the source's stable sample identity, recompute the affected minute from retained inputs and publish a new revision. Invalidate or regenerate hourly blocks that depended on the old minute revision.

If using additive corrections instead, corrections must themselves be idempotent and support the aggregate. Sum/count can be adjusted; replacing a previous maximum may require other retained values. A generic “add the late point” path cannot handle every metric type or a corrected sample.

Choose a lateness horizon aligned with source retention. A sample arriving after necessary raw inputs are deleted may require rejection, an explicitly supported repair path or a qualified historical result. Expose this policy in the API and monitor late-data rates rather than silently producing inconsistent aggregates.

7. Estimate savings with the actual summary size

One million series at one sample per ten seconds produces 8.64 billion samples/day. At a hypothetical 16 bytes per raw sample, that is 138.24 GB/day and 967.68 GB for seven days, before indexes, replication and compression.

For disjoint age tiers, days 7–30 add 23 days of minute summaries: one million × 1,440 × 23 = 33.12 billion records. At 40 bytes per summary, that is 1.3248 TB. Days 30–365 add 335 days of hourly summaries: one million × 24 × 335 = 8.04 billion records, or 321.6 GB at 40 bytes.

Total payload is approximately 2.61408 TB. Retaining 365 days of raw samples at the same assumptions would be 50.4576 TB, about 19.3 times larger. Histogram summaries may be much larger than 40 bytes, and sparse series change these totals. State that this calculation models continuously active scalar series, not every metric type equally.

8. Make query precision visible

Select resolution from requested time range and output points while honoring the requested statistic. A query for the last year's ten-second peaks cannot be answered from hourly averages. Return an explicit limitation or a supported approximation rather than upsampling and implying recovered detail.

Partial buckets are another boundary: a query beginning at 12:17 cannot get an exact 12:17–13:00 result from a 12:00–13:00 summary alone. Use finer retained data when available, align the query under a documented rule or mark the result approximate.

Test tier boundaries, late revisions, reset sequences, duplicate compaction attempts and missing samples. Compare rolled-up answers against raw reference calculations before retention deletes the oracle. Track compaction lag and historical correction rates alongside query latency.

Foundation: distinguish gauge and counter semantics. Senior: derive the mean and percentile counterexamples. Staff: keep late revisions consistent across tiers without double counting.

Score 0–2 each for metric semantics, mergeability, revision correctness, storage arithmetic and query limitations.

Sources and next steps

The tier architecture, worked examples and retention arithmetic are original. Exact counter-rate and histogram behavior depends on the chosen implementation and its documented conventions.

Continue your preparation

Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.