Try
↑ ↓ move↵ openesc close

Interview prep / Percentiles

Mid · Percentiles · System design interview question

How do the bucket boundaries of a histogram limit the accuracy of the percentiles you read from it?

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

A strong answer

A percentile read from a histogram is only known to lie in one bucket. If the system reports a single value, it interpolates inside the bucket and assumes the requests are spread evenly in it. The error is at most the width of that bucket, and often much less.

That is a problem when the bucket is wide compared with the value. With equal-width buckets, one that is narrow next to the tail can be very wide next to the median, so the median is badly estimated while the p99 is fine. Narrow buckets fix that but multiply the series you store.

Geometric buckets, where each is a fixed percentage wider than the last, give a relative error that is the same everywhere. Sketches such as DDSketch make that error a guarantee and stay mergeable across hosts. The price is memory and, in systems that store each bucket as a series, a larger number of time series.

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