← Databricks Interview Insights
I started with the obvious deque-of-timestamps approach and they immediately asked what happens under high write throughput.
Start by clarifying requirements (e.g., read/write ratio, consistency, latency) and then propose a design that separates the key-value store from the metrics tracking. For the rolling average, use a time-bucketed ring buffer with per-bucket counters and timestamps, and discuss thread safety via sharding or locks. Walk through cleanup by evicting expired buckets and explain how to compute the average efficiently.
Pro tip: Mention that the metrics tracking should be decoupled from the core KV store to avoid impacting performance, and consider using a lock-free or eventually consistent approach for the metrics if high throughput is required.
Ask about expected throughput, latency, consistency, and whether the average is per operation type or overall. Confirm if the 5-minute window is sliding or tumbling.
Choose an appropriate data structure (e.g., hash map with in-memory storage, or a persistent store like LSM tree) and discuss partitioning, replication, and consistency as needed.
Propose a ring buffer of time buckets (e.g., 1-second granularity) where each bucket holds a count and timestamp. On each operation, increment the current bucket; periodically evict buckets older than 5 minutes.
Discuss using atomic counters for buckets, sharding by time or key to reduce contention, or using read-write locks. Consider lock-free approaches like concurrent ring buffers.
Explain how to lazily or periodically remove expired buckets, and how to compute the average by summing counts of valid buckets and dividing by the window duration.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.