Design a Byte-Bounded Thumbnail Cache for Google Photos
Last updated: November 29, 2026
Quick Overview
Implement an in-memory cache for photo thumbnails whose capacity is a byte budget rather than an entry count: items have different sizes, eviction is least recently used, and items larger than a size limit are never cached.
0
0
0 solved
Implement an in-memory cache for photo thumbnails whose capacity is a byte budget rather than an entry count: items have different sizes, eviction is least recently used, and items larger than a size limit are never cached.
Thumbnail servers for Photos hold images from 2 KB to several hundred KB, so counting entries says little about memory. The interviewer wants size-aware eviction, attention to per-entry overhead, and protection from one huge item flushing the whole cache.
What the Interviewer Expects
- Track total bytes and evict until the new item fits
- Use a hash map plus ordering for O(1) operations
- Refuse items over a per-item limit
- Account for metadata overhead, not just payload
- Expose hit rate and eviction metrics
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
- How would you shard this across cores to reduce lock contention?
- How would you make a scan of cold thumbnails not flush hot ones?
- Would you cache compressed or decoded bytes?
- How do you pick the byte budget on a shared machine?
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
ThumbCache(max_bytes, max_item_bytes).put(key, data)stores bytes and evicts least recently used items until total fits.get(key)returns data orNoneand marks the key recently used. -...
High-Level Design
OrderedDict gives a hash map with a doubly linked list underneath, so move-to-end and pop-oldest are O(1). The difference from a count-bounded LRU is the eviction loop: one large put may evict many ...