Try
↑ ↓ move↵ openesc close

Interview prep / Percentiles

Senior · Percentiles · System design interview question

Design the latency measurement for a service on 500 hosts so the fleet p99.9 is accurate, cheap to store and can be sliced by endpoint.

Sketch your own answer first, then compare it with the one below.

A strong answer

Measure on each host, aggregate across hosts, and keep the aggregation mergeable.

On each host, record every request's latency into a histogram with geometric buckets or a quantile sketch, keyed by endpoint and a few low-cardinality labels. Export the bucket counts, not computed percentiles. The record path is a counter increment, so overhead per request is tiny.

In the pipeline, add bucket counts across hosts for each label set and each time window, then compute percentiles from the sum. A p99.9 over a minute needs enough requests, so decide the windows with traffic in mind and keep longer roll-ups for low-volume endpoints.

Watch the costs. Every label multiplies the series count, and every bucket is a series in some systems, so bound label cardinality and the number of buckets. Check accuracy by comparing against exact percentiles on a sample of traffic, and state the relative error of the sketch. Rule out the shortcut up front: a fleet percentile computed from per-host percentiles is wrong however carefully it is done.

Sources

Learn it by running it

The percentiles and why averages lie lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms