Track Down a Memory Leak in a Long-Running Order Event Consumer
Last updated: November 29, 2026
Quick Overview
An order event consumer's memory climbs steadily until the container is killed every few days. Describe how you would find the leak and fix it, given that the culprit is a deduplication map that never forgets event ids.
Amazon
November 29, 20260
0
0 solved
An order event consumer's memory climbs steadily until the container is killed every few days. Describe how you would find the leak and fix it, given that the culprit is a deduplication map that never forgets event ids.
Amazon services consume SQS and Kinesis streams that deliver at least once, so consumers often deduplicate, and unbounded dedupe state is a classic production leak. The interviewer wants a methodical debugging story using real tools, plus a fix that keeps the correctness the cache was providing.
What the Interviewer Expects
- Confirms a leak from a steady memory slope rather than a single spike
- Uses heap snapshots such as tracemalloc diffs to find the growing allocation site
- Explains that garbage collection cannot free objects still referenced
- Bounds the dedupe set by the redelivery window and a hard size cap
- Proposes moving durable deduplication to a store with TTL or idempotent writes
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 distinguish a leak from fragmentation or a large but stable cache?
- What size cap would you pick, and what happens to correctness if it is too small?
- How would you dedupe across many consumer hosts?
- What alarms would catch this before the out-of-memory kill?
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
- Consumer must skip events redelivered within the queue's visibility window (say 60 seconds).
- Memory must stay bounded regardless of uptime.
- Fix must be verifiable before deploy....
High-Level Design
Debugging steps: plot RSS over time to confirm linear growth; take two tracemalloc snapshots an hour apart and compare by line, which points at self.seen[event_id] = now; count entries and confirm...