Fix a Memory Leak in a Long-Running Dasher Location Consumer
Last updated: November 29, 2026
Quick Overview
A service consuming Dasher GPS pings to feed ETA predictions grows in memory until it is killed every few days. Explain how you would find the leak and implement a bounded cache of last-known locations with both a size limit and a time-to-live.
DoorDash
November 29, 20260
0
0 solved
A service consuming Dasher GPS pings to feed ETA predictions grows in memory until it is killed every few days. Explain how you would find the leak and implement a bounded cache of last-known locations with both a size limit and a time-to-live.
DoorDash processes a constant stream of Dasher location updates, and unbounded per-key state in a consumer is a common way such services fail. The interviewer checks a structured debugging approach (measure, find growth, confirm root cause) and a fix that bounds memory without hurting read latency.
What the Interviewer Expects
- Confirm the leak with memory metrics over time and correlate with traffic
- Use heap snapshots (tracemalloc or a profiler) to find the growing structure
- Identify unbounded per-key dictionaries and histories as the cause
- Bound the cache by size and by age
- Make eviction amortized O(1)
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
- How would you choose the TTL and max entries?
- What if the leak is in a C extension or native library instead of Python objects?
- How would you alert before the process is killed?
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
- Diagnose: memory grows steadily, restarts fix it temporarily.
- Fix:
update(dasher_id, lat, lng)andget(dasher_id)with at mostmax_entriesand entries older thanttltreated as missing. - ...
High-Level Design
First prove it is a leak, not a working set that is simply large: plot RSS against active Dashers. Then take two tracemalloc snapshots an hour apart and compare by line; the top growth is usually a ...