Estimate p99 Latency With a Log-Bucketed Histogram in Bounded Memory

Last updated: November 29, 2026

Quick Overview

A frontend server records the latency of every request and must report p50, p99 and p99.9 every minute without storing all samples; implement a histogram with logarithmic buckets, quantile queries with bounded relative error, and merging across servers.

Google
Software Engineering Fundamentals
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Software Engineering Fundamentals
Medium

0

0

0 solved


A frontend server records the latency of every request and must report p50, p99 and p99.9 every minute without storing all samples; implement a histogram with logarithmic buckets, quantile queries with bounded relative error, and merging across servers.

Google's monitoring stack aggregates latency distributions from huge numbers of tasks, so exact percentiles from raw samples are not an option. The interviewer checks that you know why averages hide tail latency and how bucketed histograms trade precision for constant memory and mergeability.

What the Interviewer Expects
  • Explain why averaging per-server p99s is wrong
  • Use logarithmic bucket boundaries with fixed relative error
  • Compute a quantile by walking cumulative counts
  • Merge histograms by adding bucket counts
  • State the error bound and memory cost
Key Topics to Cover
percentiles
histograms
tail latency
monitoring
mergeable sketches
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How would you choose the growth factor for a 1% error target?
  • How do you handle a sample of zero or a negative value?
  • Compare this with t-digest or HdrHistogram.
  • How would you reset or decay old data for a sliding window?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements
  • LatencyHistogram(gamma) with growth factor gamma (for example 1.02) covering 1 microsecond to 100 seconds.
  • record(ms), quantile(q), merge(other), count.
  • Relative error of any reporte...
High-Level Design

Bucket k covers (gamma^(k-1), gamma^k]. A value v maps to k = ceil(log(v) / log(gamma)). Reporting the bucket midpoint 2 * gamma^k / (gamma + 1) bounds relative error by `(gamma - 1)/(gamma ...


Submit Your Answer
Markdown supported