Implement a Key-Value Cache with Per-Entry Expiration
Last updated: August 21, 2026
Quick Overview
Implement a key-value cache that supports per-entry expiration, allowing entries to automatically expire after a specified duration.
Netflix
August 21, 20262
0
22 solved
Implement a key-value cache that supports per-entry expiration, allowing entries to automatically expire after a specified duration.
This question is typically asked during the technical screening round to evaluate a candidate's understanding of data structures, algorithms, and system design principles. The interviewer is looking for the candidate's ability to design a functional cache system that efficiently handles data storage, retrieval, and expiration, while also considering performance and memory usage.
What the Interviewer Expects
- Explain the choice of data structures for the cache implementation.
- Describe how to manage expiration for each cache entry.
- Discuss the strategies for handling cache hits and misses.
- Consider thread safety and concurrent access in the design.
- Provide a clear and efficient implementation in code.
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 handle cache eviction when the cache reaches its limit?
- What strategies can you implement to optimize cache performance?
- How would you modify your design to support distributed caching?
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
To implement a key-value cache with per-entry expiration, we need to support basic operations such as storing, retrieving, and deleting key-value pairs. Each entry should have a specified expiration t...
High-Level Design
The cache can be implemented using a combination of a hash map and a priority queue. The hash map will store the key-value pairs along with their expiration timestamps. The priority queue will help ma...