Track p99 Latency Across a Fleet in Fixed Memory
Last updated: November 29, 2026
Quick Overview
Each host serving the product detail page must report p50, p99, and p99.9 latency every minute, and the numbers must merge across thousands of hosts. Implement a fixed-memory histogram with bounded relative error that supports merging and quantile queries.
Amazon
November 29, 20260
0
0 solved
Each host serving the product detail page must report p50, p99, and p99.9 latency every minute, and the numbers must merge across thousands of hosts. Implement a fixed-memory histogram with bounded relative error that supports merging and quantile queries.
Amazon teams alarm on tail latency rather than averages, and CloudWatch-style percentile metrics must aggregate across a fleet. The interviewer checks why you cannot average percentiles, how log-scale buckets bound relative error, and how memory stays constant regardless of traffic.
What the Interviewer Expects
- Explains why averaging per-host p99 values is wrong
- Uses logarithmic buckets so error is relative, not absolute
- Derives bucket count from error target and value range
- Makes histograms mergeable by adding counts
- Handles zero, tiny, and out-of-range values explicitly
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How many buckets do you need for 1 percent error between 10 microseconds and 60 seconds?
- How would you send this over the wire compactly?
- How does this compare with t-digest or HDR histogram?
- How would you compute the p99 over the last hour from per-minute histograms?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
add(ms)on the request path must be with no allocation.- Quantile error at most 1 percent of the true value.
- Histograms from different hosts and minutes merge exactly.
- Memory independe...
High-Level Design
Use buckets whose boundaries grow geometrically by ; a value falls in bucket . Reporting the point $\frac{2\gamma^{i+1}}{\gamma+1...