Build a Byte-Bounded LRU Cache Keyed by Content Fingerprint

Last updated: November 29, 2026

Quick Overview

Implement a read cache for vdisk blocks where identical content written by different VMs is stored once: `put(vdisk, offset, data)` and `get(vdisk, offset)` with a total byte capacity, LRU eviction by content, and correct cleanup when a logical block is overwritten with different data.

Nutanix
Coding & Algorithms
Software Engineer
Nutanix
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Implement a read cache for vdisk blocks where identical content written by different VMs is stored once: `put(vdisk, offset, data)` and `get(vdisk, offset)` with a total byte capacity, LRU eviction by content, and correct cleanup when a logical block is overwritten with different data.

The storage fabric keeps a deduplicated content cache in memory, so hundreds of cloned VDI desktops reading the same OS blocks share one cached copy. An onsite coding round uses this to test whether you can maintain two indexes (logical to fingerprint, fingerprint to logical keys) in sync while enforcing a byte budget.

What the Interviewer Expects
  • Separates the logical key index from the content store
  • Charges capacity once per unique fingerprint
  • Evicts by LRU over content and removes every logical key pointing at it
  • Unlinks the old fingerprint when a block is overwritten
  • Gives O(1) average get and put
Key Topics to Cover
LRU cache
OrderedDict
deduplication
reference tracking
hashing
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • SHA-1 collisions are possible in principle. When would you verify bytes on a hit?
  • How would you shard this cache across cores to avoid one global lock?
  • Should a fingerprint shared by 500 VMs be harder to evict than one used once?
  • How do you size the cache split between memory and SSD tiers?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Capacity is in bytes, not entries. Two logical keys with the same bytes share one stored copy and count once. get refreshes recency of the content. Overwriting (vdisk, offset) with different bytes...

High-Level Design

Three structures:

  • data: OrderedDict fingerprint to bytes, ordered by recency.
  • logical: (vdisk, offset) to fingerprint.
  • refs: fingerprint to the set of logical keys using it.

On put,...


Submit Your Answer
Markdown supported

Related Questions