Shrink a Python Price History Cache That Exhausts Host Memory

Last updated: November 29, 2026

Quick Overview

A service keeps per-ASIN price history as lists of small Python objects and runs out of memory. Explain where the bytes go and reduce the footprint by an order of magnitude without changing the API callers use.

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

0

0

0 solved


A service keeps per-ASIN price history as lists of small Python objects and runs out of memory. Explain where the bytes go and reduce the footprint by an order of magnitude without changing the API callers use.

Price tracking and deal eligibility checks need recent price history in memory, and Python's per-object overhead surprises many engineers. The interviewer checks whether you can estimate memory from first principles and measure it, then pick a representation that matches the access pattern.

What the Interviewer Expects
  • Explains per-object overhead: header, attribute storage, boxed ints, list pointers
  • Measures with tracemalloc rather than guessing
  • Uses __slots__ as a first step and explains its limits
  • Moves to columnar packed arrays for the large win
  • Keeps queries efficient on the new layout
Key Topics to Cover
memory profiling
Python object model
__slots__
columnar storage
packed arrays
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
  • When would you move this out of process into a cache such as ElastiCache?
  • How would you store prices that exceed 32 bits or need currency?
  • How would you compress old history further, for example with delta encoding?
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
  • Each point is a timestamp and a price in cents; histories are append-only and time ordered.
  • Query: lowest price since a timestamp.
  • Reduce memory at least 10x....
High-Level Design

A PricePoint object costs its object header and attribute storage, two boxed ints (about 28 bytes each when not cached small ints), plus an 8-byte pointer in the list. Measured: about 156 bytes per ...


Submit Your Answer
Markdown supported