Design a concurrent latency percentile tracker
Company: Netflix
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: hard
Interview Round: Technical Screen
Design a **thread-safe** `LatencyTracker` class that supports:
1. **Recording samples**
- Input: `timestamp` (e.g., epoch millis) and `latencyMs` (integer milliseconds)
- Operation: `addSample(timestamp, latencyMs)`
2. **Querying percentile latency over a time window**
- Input: a time window and a percentile
- Window can be specified as `[startTimestamp, endTimestamp]` (inclusive)
- Percentile `p` is in `(0, 100]` (e.g., 50, 90, 95, 99)
- Operation: `getPercentile(startTimestamp, endTimestamp, p)`
- Output: the latency value (ms) at percentile `p` among samples whose timestamps fall inside the window.
Additional requirements:
- The class must support **concurrent** writers (`addSample`) and readers (`getPercentile`).
- Clarify any assumptions you need (e.g., maximum query window/retention, acceptable approximation, out-of-order timestamps).
Quick Answer: This question evaluates understanding of concurrent data structures, thread-safety, time-windowed metrics aggregation, and percentile computation for latency tracking within the Software Engineering Fundamentals domain.