Track Seen Video IDs in Compact Memory With a Bitset
Last updated: November 29, 2026
Quick Overview
A service must record which of up to 2 billion dense integer video IDs a batch job has processed; implement a bitset with set, test and count operations and compare its memory cost with a hash set.
0
0
0 solved
A service must record which of up to 2 billion dense integer video IDs a batch job has processed; implement a bitset with set, test and count operations and compare its memory cost with a hash set.
YouTube-scale batch jobs often need membership over dense integer ID spaces, and a Python set or Java HashSet of billions of ints does not fit on a worker. The screen checks basic bit math and quick memory estimation.
What the Interviewer Expects
- Map an id to a byte index and bit offset
- Implement set, clear, test and population count
- Estimate memory for bitset versus hash set
- Validate the id range
- Know when a bitset is the wrong tool
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
- What if IDs are sparse 64-bit values instead of dense?
- How would you merge bitsets from 1000 workers?
- When would you use a Bloom filter or Roaring bitmap instead?
- How would you persist and memory map the bitset?
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
Bitset(n)supports ids in[0, n).add(i),discard(i),contains(i),count(), andunion(other).- Out-of-range ids raise
IndexError....
High-Level Design
Id i lives in byte i >> 3 at bit i & 7. Setting is buf[i>>3] |= 1 << (i & 7), testing is an AND. For 2 billion ids that is 2e9 / 8 = 250 MB, which fits on any worker. A Java HashSet<Integer>...