Byte-Budgeted LRU Cache With Pinned Game Assets

Last updated: November 29, 2026

Quick Overview

Implement an asset cache with a byte budget that supports get, put(key, size), pin and unpin: put evicts least recently used unpinned assets until the new asset fits, and refuses the insert without evicting anything if pinned assets make it impossible.

PlayStation
Software Engineering Fundamentals
Software Engineer
PlayStation
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Medium

0

0

0 solved


Implement an asset cache with a byte budget that supports get, put(key, size), pin and unpin: put evicts least recently used unpinned assets until the new asset fits, and refuses the insert without evicting anything if pinned assets make it impossible.

Console games and the PS5 system UI stream textures and other assets into fixed memory, where some assets (the current level, the UI shell) must never be evicted. The interviewer checks LRU mechanics, byte accounting across resizes, and that a failed insert leaves the cache untouched.

What the Interviewer Expects
  • Use an ordered map for O(1) recency updates
  • Track used bytes and pinned bytes separately
  • Decide feasibility before evicting so a failed put has no side effects
  • Support re-put of an existing key with a new size
  • Use pin counts so nested pins work
  • Discuss the cost of skipping pinned entries during eviction
Key Topics to Cover
LRU cache
OrderedDict
Memory budget
Reference counting
Invariants
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
  • Eviction skips pinned entries in LRU order; how would you avoid an O(n) scan when many assets are pinned?
  • How would you make this thread safe for a loader thread and a render thread?
  • How would you change the policy if some assets are far more expensive to reload than others?
  • What metrics would you expose to tune the budget?
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

Operations: get(key) marks it most recent; put(key, size) inserts or resizes; pin/unpin with counts. Invariant: used <= budget after every call. A put that cannot fit even after evicting eve...

High-Level Design

An OrderedDict from key to size, oldest first, gives O(1) move-to-end and pop. Keep used and pinned_bytes. Feasibility check: the bytes that can never be freed are pinned assets other than the k...


Submit Your Answer
Markdown supported

Related Questions