LRU Cache With Per-Entry TTL for Profile Lookups

Last updated: November 29, 2026

Quick Overview

Implement an in-process cache for profile lookups with get(key) and put(key, value, ttl): at most capacity entries, evicting the least recently used on overflow, and treating entries past their TTL as missing. All operations should be O(1).

LinkedIn
Software Engineering Fundamentals
Software Engineer
LinkedIn
November 29, 2026
Software Engineer
Technical Screen
Software Engineering Fundamentals
Medium

0

0

0 solved


Implement an in-process cache for profile lookups with get(key) and put(key, value, ttl): at most capacity entries, evicting the least recently used on overflow, and treating entries past their TTL as missing. All operations should be O(1).

Profile reads at LinkedIn are extremely hot, so services front their stores with local caches. This fundamentals question checks O(1) LRU design, lazy expiry, testable time, and the trade-offs of in-process caching versus a shared cache.

What the Interviewer Expects
  • Uses an ordered hash map (or hash map plus doubly linked list) for O(1) LRU
  • Moves an entry to most recent on get and put
  • Expires lazily on access and evicts expired entries before live ones when possible
  • Injects a clock for deterministic tests
  • Discusses memory sizing, stampedes, and staleness against the source of truth
Key Topics to Cover
LRU cache
TTL expiry
ordered dict
dependency injection
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 prevent a thundering herd when a popular key expires?
  • How would you invalidate entries when a member edits their profile?
  • When would you choose a shared cache like Couchbase or Redis over this?
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

put inserts or replaces with a TTL in seconds. get returns the value or None if absent or expired. Capacity counts entries, expired or not, until they are removed. A clock function is injectable...

High-Level Design

OrderedDict gives O(1) move_to_end and popitem(last=False), which is the hash map plus doubly linked list design without writing pointers. Each value is stored as (value, expires_at). On get, ...


Submit Your Answer
Markdown supported