LRU Feature Cache With Per-Request Staleness Bounds
Last updated: November 29, 2026
Quick Overview
Design and implement an in-memory LRU cache of computed feature values where each read passes the maximum staleness it will accept, so the same cached value can satisfy a lenient caller and be rejected for a strict one.
Chalk
November 29, 20260
0
0 solved
Design and implement an in-memory LRU cache of computed feature values where each read passes the maximum staleness it will accept, so the same cached value can satisfy a lenient caller and be rejected for a strict one.
Chalk lets a feature declare how stale a cached value may be before the engine recomputes it from the source, which trades latency against freshness. The interviewer wants a correct LRU with O(1) operations, plus careful handling of out-of-order writes and of what to do with stale hits.
What the Interviewer Expects
- Uses an ordered map or hash map plus doubly linked list for O(1) get, put and eviction
- Stores the compute time with the value and checks staleness at read time, not with a fixed TTL
- Does not let an older computation overwrite a fresher value
- Keeps stale entries for more lenient readers instead of deleting them on a miss
- Discusses thread safety and memory bounds
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 make this safe under concurrent requests without one global lock becoming a bottleneck?
- How would you avoid a thundering herd when a hot key goes stale and hundreds of requests recompute it?
- Should capacity be measured in entries or bytes for features that are vectors?
- How would you layer this in front of a shared Redis online store?
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
put(key, value, computed_at) and get(key, now, max_staleness). A hit counts only if now - computed_at <= max_staleness. Capacity is fixed in entries, with least recently used eviction. Reads and...
High-Level Design
Python's OrderedDict gives a hash map with an intrusive linked list: move_to_end marks use and popitem(last=False) evicts the oldest. The key design choice is that staleness belongs to the read,...