Try
↑ ↓ move↵ openesc close

Interview prep / Percentiles

Mid · Percentiles · System design interview question

Why is averaging each host's p99 the wrong way to get the fleet p99, and what should you do instead?

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

A strong answer

A percentile describes the shape of a whole group of requests. The shape of the union of several groups is not the average of their shapes. The average also gives a host with a sliver of the traffic the same weight as the busiest one, and the answer can come out too high or too low depending on who is slow.

A host with ten requests and a terrible p99 would count as much as a host with ten thousand. Weighting by traffic fixes that part but not the rest, because the merged p99 depends on how the slow requests are spread over hosts.

The right approach is to export a histogram from every host, add the bucket counts, and read the percentile from the sum. Mergeable sketches do the same with bounded error. If only percentiles are stored, the best you can do is an upper bound from the maximum of the host values.

This bug survives testing because test hosts are identical, and identical hosts agree with their own average.

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