← Questions
Concurrent latency percentile tracker
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Netflix's technical phone screen, last asked Feb 2026. It tests concurrency, percentiles and data structure design.
Build a component that records request latencies from many threads at once and answers percentile queries such as p50, p95 and p99 over recent traffic. Recording sits on the request path, so it must be cheap and must not make threads wait on each other.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
record(latency_ms: int) -> Noneis called concurrently from many threads. -
percentile(p: float) -> intreturns the nearest-rank percentile over the samples recorded in the lastwindow_seconds(the smallest value such that at leastp% of samples are at or below it), or-1when there are no samples.
Example
# all within the window
for x in [12, 7, 30, 15, 9, 100, 22, 18, 11, 40]: record(x)
percentile(50) -> 15
percentile(90) -> 40
percentile(99) -> 100
Constraints
- Millions of
recordcalls per second across threads; queries a few times per second. - Latencies from 0 to 60,000 ms.
Clarifying questions
- Must percentiles be exact, or is a bounded relative error (say 1%) acceptable?
- Is the window sliding (last 60 seconds) or reset at fixed intervals?
- How many threads write, and how often are percentiles read?
- Is memory bounded, and does the process run for months?
What a strong answer covers
- The exact baseline (store all samples, sort or select on query) and why it fails on memory and lock contention.
- Bucketed histograms (fixed or logarithmic buckets) giving bounded error and
O(buckets)queries; sketches such as HDR histogram, t-digest or DDSketch, and their error guarantees. - Sliding windows as a ring of per-second (or per-interval) histograms that are merged on query and expired as time moves.
- Low-contention writes: per-thread or striped histograms with atomic counters, merged on read, and why one global lock on the hot path is unacceptable.
- Correct nearest-rank math, empty windows, and tests that compare against an exact implementation.
Follow-ups
- Merge percentiles from many servers into one fleet-wide p99.
- Add per-endpoint tracking for thousands of endpoints without blowing memory.
- Show why averaging p99s from several hosts is wrong.
Where it's asked
- Netflix · Technical phone screen · Last asked Feb 202660 min · Coding, practical problem solving, or SQL and pipeline design, depending on the org
What it tests
concurrency · percentiles · data structure design
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
