← Databricks Interview Insights

Databricks·Software Engineer·Onsite - System Design / Architecture·Senior

SeniorPrefer not to say
Jul 2026

Summary

Databricks system design interview focused on building an in-memory key-value store for QPS tracking. The sliding window angle made it more interesting than a typical design question, and the follow-ups on space optimization pushed things further than I expected.

Questions Asked (2)

Q1

Design an in-memory key-value store that can calculate queries per second (QPS) over a rolling 5-minute window.

System DesignAlgorithms & Data Structures
Author's notes

I went with a sliding window approach pretty quickly, which felt right.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements: what operations are needed (put, get, query QPS), expected scale, and whether the store itself is the system being measured or if it's a separate component. Then design a data structure that efficiently tracks events over a sliding window, such as a ring buffer of per-second counters, and discuss trade-offs between precision, memory, and performance.

Pro tip: Mention that you would use a circular buffer of 300 buckets (one per second) to achieve O(1) updates and queries, and highlight that this avoids the overhead of storing individual timestamps. Also, proactively discuss how to handle concurrency and clock drift, showing awareness of production concerns.

1. Clarify Requirements and Scope

Ask questions to understand the expected QPS range, read/write ratio, latency requirements, and whether the QPS calculation is for the store's own operations or for external queries. Confirm if approximate or exact counts are needed.

2. Choose a Sliding Window Approach

Decide between a fixed window with buckets (e.g., per-second counters) and a true sliding window (e.g., timestamp queue). For most cases, a ring buffer of per-second counters offers a good balance of simplicity and efficiency.

3. Design the Data Structures

Propose a circular array of size 300 (for 5 minutes at 1-second granularity), where each bucket stores a count and a timestamp. On each query, increment the current bucket; on QPS calculation, sum the counts of buckets within the last 5 minutes and divide by 300.

4. Address Edge Cases and Concurrency

Discuss handling of bucket expiration, thread safety (e.g., using atomic operations or locks), and clock adjustments. Consider using a lock-free approach or sharding for high concurrency.

5. Analyze Trade-offs and Optimizations

Compare with alternatives like a queue of timestamps (more memory, exact) or a two-bucket approximation. Mention potential optimizations such as lazy aggregation or using a time-wheel.

Key Points to Mention

  • Use a circular buffer of per-second counters to achieve O(1) time for both updates and queries.
  • The window size is 300 seconds; each bucket represents one second and stores a count and a timestamp to detect staleness.
  • For QPS calculation, sum the counts of all valid buckets in the last 5 minutes and divide by 300.
  • Handle concurrency with atomic operations or fine-grained locks; consider sharding for high throughput.
  • Discuss memory usage: 300 buckets * (counter + timestamp) is negligible, making it memory-efficient.
  • Mention that the approach can be extended to other window sizes or granularities by adjusting the number of buckets.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

How would you reduce memory usage in your QPS tracking design?

System DesignTechnical Trade-offs
Author's notes

This follow-up tripped me up more than the main question.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements and constraints of the QPS tracking system, such as the required accuracy, query patterns, and data retention. Then, systematically discuss memory reduction techniques like probabilistic data structures, time-windowed aggregation, and efficient encoding, while highlighting trade-offs between memory, accuracy, and latency.

Pro tip: Emphasize that memory reduction often involves trade-offs; showing awareness of when to sacrifice accuracy for memory (e.g., using sketches) and when to use exact methods (e.g., for billing) demonstrates maturity. Also, mention that monitoring and profiling are crucial to identify actual memory bottlenecks before optimizing.

1. Clarify Requirements and Constraints

Ask about the scale (QPS, number of keys), required accuracy, query patterns (e.g., real-time vs. historical), and retention period. This determines which memory reduction techniques are applicable.

2. Choose Appropriate Data Structures

Select memory-efficient data structures such as Count-Min Sketch, HyperLogLog, or Bloom filters for approximate counting, or use arrays with delta encoding for exact counts if accuracy is critical.

3. Aggregate and Downsample Data

Use time-based aggregation (e.g., per-second, per-minute) and downsampling to reduce the number of stored data points. Consider sliding windows or tumbling windows to limit memory footprint.

4. Optimize Storage and Encoding

Apply compression techniques (e.g., run-length encoding, delta encoding) and use compact serialization formats. Store data in memory-mapped files or off-heap memory if necessary.

5. Discuss Trade-offs and Monitoring

Explain the trade-offs between memory, accuracy, and latency. Mention the importance of monitoring memory usage and profiling to validate optimizations.

Key Points to Mention

  • Probabilistic data structures (Count-Min Sketch, HyperLogLog) for approximate counting with bounded memory.
  • Time-windowed aggregation and downsampling to reduce data volume.
  • Compression and encoding techniques (delta encoding, run-length encoding).
  • Trade-offs between memory, accuracy, and query latency.
  • Use of off-heap or memory-mapped storage to reduce heap pressure.
  • Monitoring and profiling to identify memory hotspots and validate optimizations.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.