I passed my Databricks technical phone screen, which focused on implementing a hit counter to track QPS for key-value store operations. The problem started with three APIs: put, get, and get_load, with a fixed five-minute measurement window. I discussed both queue-based and ring-buffer approaches before implementing the ring buffer. The most interesting part was a follow-up about calculating QPS correctly when the server had been running for less than five minutes.
Interview Details
Coding: Hit Counter and Sliding Window QPS
Question 1 — Implement a Key-Value Store With QPS Tracking
The interviewer started by giving me three APIs:
put(key, value)
get(key)
get_load()
put(key, value)
get(key)
get_load()
The put and get methods represented key-value store operations. The get_load() method needed to report the queries per second (QPS) for both operations separately. In my implementation, I used two separate methods to retrieve the read and write QPS rather than a single get_load() method. The interviewer allowed me to ask clarifying questions before implementing the solution.
Clarification — Fixed Five-Minute Window
The QPS calculation needed to use a fixed measurement window of five minutes. In other words, the system should track the number of operations occurring during the most recent 300 seconds.
I confirmed with the interviewer that I could use the system clock for timestamps. I chose Python's time.time(). I pointed out that relying on the actual system clock would make testing less convenient, but the interviewer said that was fine.
Question 2 — Compare Queue and Ring Buffer Approaches
Before coding, I proposed two possible approaches.
Approach 1 — Queue With Running Count
My first idea was to maintain a queue containing timestamp-count pairs: (timestamp, count). I would also maintain a running total of the operations currently included in the measurement window. As time advanced, outdated entries would be removed from the queue, and their counts would be subtracted from the running total. This would let me calculate the current request volume without repeatedly counting all the entries.
Approach 2 — Ring Buffer With Time Buckets
My second proposal was to use a
Unlock Full Details
Create a free account to unlock this interview experience report.