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
Software Engineering Fundamentals
Software Engineer
Netflix
August 21, 2026
Software Engineer
Technical Screen
Software Engineering Fundamentals
Easy

2

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
Data Structures
Cache Implementation
Expiration Management
Concurrency
Performance Optimization
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported

Related Questions