Bounded LRU Price Cache With Per-Entry Expiry

Last updated: November 29, 2026

Quick Overview

Implement an in-process cache for product prices on listing pages that holds at most N entries, evicts the least recently used item when full, expires entries after a TTL, and supports explicit invalidation when a seller changes a price.

Flipkart
Software Engineering Fundamentals
Software Engineer
Flipkart
November 29, 2026
Software Engineer
Phone Screen
Software Engineering Fundamentals
Easy

0

0

0 solved


Implement an in-process cache for product prices on listing pages that holds at most N entries, evicts the least recently used item when full, expires entries after a TTL, and supports explicit invalidation when a seller changes a price.

Flipkart search and browse pages render hundreds of product cards per request, and hitting the pricing service for each is too slow during sale traffic. A phone screen uses this to check data structure choice for O(1) LRU, memory bounding, and the trade-off between staleness and load.

What the Interviewer Expects
  • Use a hash map plus recency order (OrderedDict or map plus doubly linked list) for O(1) operations
  • Bound memory by entry count and evict LRU
  • Expire entries by TTL with an injectable clock
  • Provide invalidation for price changes
  • Track hit, miss and eviction counts
Key Topics to Cover
LRU eviction
TTL expiry
hash map plus linked list
cache invalidation
memory bounds
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 make this thread-safe without one big lock hurting throughput?
  • Many keys expire at the same moment and the pricing service gets a spike. How do you prevent it?
  • When is a per-pod cache the wrong choice compared to a shared Redis tier?
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

get(key) returns the price or None on miss or expiry. put(key, value) inserts or refreshes. Size never exceeds max_entries. Entries older than ttl_seconds are not served. invalidate(key) r...

High-Level Design

OrderedDict keeps insertion order and supports move_to_end and popitem(last=False) in O(1), which is exactly a hash map plus doubly linked list. Each value stores its expiry deadline. Expiry is ...


Submit Your Answer
Markdown supported

Related Questions