Drop Duplicate Events by Insert ID in a Streaming Ingester
Last updated: November 29, 2026
Quick Overview
Design a component that receives events with (project_id, insert_id, event_time) and accepts each unique event once, discarding retries that repeat an insert_id seen within a bounded event-time window, using bounded memory.
Mixpanel
November 29, 20260
0
0 solved
Design a component that receives events with (project_id, insert_id, event_time) and accepts each unique event once, discarding retries that repeat an insert_id seen within a bounded event-time window, using bounded memory.
Mobile SDKs retry on flaky networks, so Mixpanel's ingestion sees the same event several times and deduplicates on insert_id. The interviewer wants a correct bounded-memory structure and a clear statement of what happens to events that arrive after the window.
What the Interviewer Expects
- Key on (project, insert_id), not insert_id alone
- Bound memory with an event-time watermark and ordered eviction
- State the guarantee precisely: exact within the window, deferred to batch beyond it
- O(1) amortized per event
- Discuss trade-off between window size and memory
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you shard this across ingestion nodes so duplicates land on the same node?
- Memory is still too large for the biggest projects: where would a Bloom filter help and what does a false positive cost here?
- How does a later compaction step finish deduplication for events outside the window?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
accept(project, insert_id, ts) returns True if the event should be written. Two events are duplicates if they share project and insert_id. Real retries land within minutes, so exact dedupe inside a ...
High-Level Design
Keep an insertion-ordered map from key to event time and a watermark equal to the highest event time seen. When the watermark advances, pop from the front while entries are older than watermark - W....