Track Down Steady Memory Growth in a Long-Running Feed Worker

Last updated: November 29, 2026

Quick Overview

A Python worker that enriches feed candidates for Toutiao grows from 2 GB to 12 GB over a day until it is OOM-killed; explain how you would find the cause and fix a typical culprit.

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

0

0

0 solved


A Python worker that enriches feed candidates for Toutiao grows from 2 GB to 12 GB over a day until it is OOM-killed; explain how you would find the cause and fix a typical culprit.

ByteDance interviews for backend and infrastructure roles often include a debugging scenario grounded in production. The interviewer is checking a systematic method (measure, isolate, confirm, fix, guard) rather than guessing, and familiarity with real tools.

What the Interviewer Expects
  • Confirm it is a leak and not normal warm-up by graphing RSS over time
  • Use tracemalloc snapshots or a heap profiler to diff allocations
  • Identify common culprits: unbounded caches, global lists, reference cycles with finalizers, native extension leaks
  • Fix with bounded structures and verify the slope flattens
  • Add a guardrail such as memory alerts or a max-requests restart
Key Topics to Cover
memory leaks
profiling
caching
production debugging
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
  • tracemalloc shows nothing growing but RSS still climbs: what next?
  • How would you reproduce this in a test environment without waiting a day?
  • When is periodically restarting workers an acceptable fix?
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

Clarify: does memory grow linearly with requests or with time, does it ever drop, and did it start with a specific deploy? Check whether all replicas grow or only some, and whether RSS growth matches ...

High-Level Design

Method: (1) plot RSS and request count; (2) take tracemalloc snapshots an hour apart and diff by line; (3) inspect the top growth sites; (4) if Python heap is flat but RSS grows, use a native profiler...


Submit Your Answer
Markdown supported