Reference Counting Shared Chunks When Snapshots Expire
Last updated: November 29, 2026
Quick Overview
Implement a chunk store where snapshots reference deduplicated chunks, and expiring a snapshot returns exactly the chunks no other snapshot still uses.
Rubrik
November 29, 20260
0
0 solved
Implement a chunk store where snapshots reference deduplicated chunks, and expiring a snapshot returns exactly the chunks no other snapshot still uses.
After dedupe, one chunk on a Rubrik cluster may back hundreds of snapshots, so space can only be reclaimed when the last reference goes away. The interviewer checks a correct reference count, including repeated chunks within one snapshot, and awareness of how this goes wrong at scale.
What the Interviewer Expects
- Keep a count per chunk, not a boolean
- Count repeats within a single snapshot
- Free only at zero
- Reject duplicate snapshot ids
- Mention crash consistency of counts
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- The process crashes halfway through expire. How do you avoid leaked or wrongly freed chunks?
- Why do many storage systems prefer mark-and-sweep over reference counts?
- How would you report how much space expiring a snapshot would free before doing it?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
add_snapshot(id, chunks) records references; expire(id) removes them and returns hashes whose count reached zero. A chunk listed twice in one snapshot (two identical blocks) counts twice....
High-Level Design
A Counter from chunk hash to references, plus the list of chunks per snapshot so expire knows what to decrement....