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
- Charles Masson, Jee E. Rim, Homin K. Lee (2019). DDSketch: A Fast and Fully-Mergeable Quantile Sketch with Relative-Error Guarantees.
- Betsy Beyer, Chris Jones, Jennifer Petoff, Niall Richard Murphy (2016). Site Reliability Engineering, chapter: Monitoring Distributed Systems.