Cut Memory for Millions of Video Records in a Python Service
Last updated: November 29, 2026
Quick Overview
A Python ranking sidecar keeps 20 million small video metadata objects (id, views, duration) in memory and uses far more RAM than expected; explain why and show two ways to shrink it.
ByteDance
November 29, 20260
0
0 solved
A Python ranking sidecar keeps 20 million small video metadata objects (id, views, duration) in memory and uses far more RAM than expected; explain why and show two ways to shrink it.
ByteDance runs many Python services around its recommendation stack, and knowing where memory goes is a basic fundamentals check in their phone screens. The interviewer wants per-object overhead explained concretely and practical fixes like __slots__ and columnar arrays.
What the Interviewer Expects
- Explain per-object overhead: object header plus a per-instance __dict__
- Show __slots__ removes the instance dict
- Show columnar storage with array or NumPy stores raw machine integers
- Measure rather than guess, using sys.getsizeof or tracemalloc
- Mention trade-offs such as no dynamic attributes
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
- When would you move this data out of process entirely?
- How does NumPy compare to the array module here?
- Strings like titles dominate memory: what then?
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
Clarify: how many records, which fields, read patterns (random lookups by id or scans), and whether records change. Here 20 million records of three integers should need roughly 20M x 20 bytes = 400 M...
High-Level Design
Each plain object carries a header plus a separate dict hash table, and each int field is itself a boxed object. slots replaces the dict with fixed slots inside the object. For scan-heavy work...