← Databricks Interview Insights
The put and delete parts are easy enough that you might spend too long on them and then scramble when they ask about the QPS tracking.
Start by clarifying requirements (scale, consistency, latency, data size) and then design the core key-value store with a simple in-memory hash map and persistence options. For the average QPS over the last five minutes, propose a sliding window approach using a ring buffer of per-second counters, and discuss trade-offs between accuracy and memory. Finally, address concurrency, scalability, and potential optimizations like sharding or using a time-series database.
Pro tip: Demonstrate awareness of real-world constraints by discussing how to handle high cardinality and memory overhead of per-second counters, and suggest approximate methods like exponential moving averages if exact precision isn't critical.
Ask about expected scale (QPS, data size), consistency needs, latency requirements, and whether the QPS metric needs to be exact or approximate. This shows you think before coding.
Propose a basic in-memory hash map for fast put/delete, and discuss persistence options (e.g., write-ahead log, LSM trees) if durability is needed. Mention concurrency control (e.g., sharding, locks).
Use a sliding window of per-second counters (e.g., a ring buffer of 300 counters) to track queries. On each query, increment the current second's counter. To get average QPS, sum the counters and divide by 300.
Discuss how to scale the QPS tracking across multiple nodes (e.g., aggregate per-node counters) and trade-offs between memory usage and accuracy (e.g., using buckets of 10 seconds instead of 1 second).
Consider optimizations like using atomic counters for thread safety, handling clock skew, and resetting counters. Mention alternative approaches like using a time-series database or approximate algorithms (e.g., EMA).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.