Design an LFU Cache for Db2 Buffer Pool Pages
Last updated: November 29, 2026
Quick Overview
Implement a fixed-capacity page cache with O(1) get and put that evicts the least frequently used page, breaking ties by least recently used.
IBM
November 29, 20260
0
0 solved
Implement a fixed-capacity page cache with O(1) get and put that evicts the least frequently used page, breaking ties by least recently used.
Db2 buffer pools decide which pages stay in memory, and an LFU cache with LRU tie-breaking is a demanding IBM onsite design-a-structure problem. The interviewer checks that every operation is O(1), that the minimum frequency is tracked without scanning, and that tie-breaking is correct.
What the Interviewer Expects
- Map key to value and frequency
- Group keys by frequency in ordered buckets
- Track the current minimum frequency
- Reset min frequency to 1 on new inserts
- Keep every operation O(1)
- Discuss why LFU alone can starve new hot pages
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you add frequency aging so old hot pages eventually leave?
- How does this compare to LRU-K or ARC?
- How would you make it thread safe with low contention?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
get(page) returns the cached value or -1 and counts as a use. put(page, value) inserts or updates; when full, evict the page with the lowest use count, and among those the one used longest ago. Ca...
High-Level Design
Keep vals (page to value), freq (page to count), and buckets, a dictionary from count to an OrderedDict of pages in recency order. Track min_f. A touch moves a page from bucket f to bucket f...