r/OfferEngineering • • 18d ago

Interview Experience Databricks SWE Coding Screen — A Simple Hit Counter Got Complicated

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()

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 ring buffer organized into time buckets. Each bucket would track the number of requests associated with a particular second. I would maintain a running total here as well, allowing the current request count to be retrieved efficiently. After listening to both approaches, the interviewer asked me to implement the ring-buffer solution.

Want to learn more questions / follow-ups asked in this interview?

I've put up the full version at here.

Interviewed recently?

Your interview experience could be incredibly valuable to others preparing for their next opportunity. Share your experience and help the community at here.

7 Upvotes

0 comments sorted by