Throttle Duplicate Push Notifications With a Per-Key Cooldown
Last updated: November 29, 2026
Quick Overview
Design a throttle that receives (timestamp, notification_key) pairs in time order and returns whether the notification should be sent. A key may be sent at most once every 10 seconds, and suppressed attempts do not reset the cooldown.
Meta
November 29, 20260
0
0 solved
Design a throttle that receives (timestamp, notification_key) pairs in time order and returns whether the notification should be sent. A key may be sent at most once every 10 seconds, and suppressed attempts do not reset the cooldown.
Meta notification pipelines must avoid spamming users with the same 'X liked your photo' alert, so this appears as a quick design-a-class question. The interviewer checks the cooldown semantics, the hash map choice, and whether you notice memory grows without cleanup.
What the Interviewer Expects
- Confirm whether a blocked attempt restarts the cooldown
- Store the next allowed time per key in a hash map
- Return a boolean in O(1)
- Propose a cleanup strategy for stale keys
- Talk about behavior when two servers share the same keys
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 do you bound memory when millions of distinct keys arrive?
- What changes if the cooldown is per user per key rather than global?
- How would this work across many notification servers?
- What if events can arrive out of order by a few seconds?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
should_send(t, key)returns True ifkeywas not sent in the previous 10 seconds.- Timestamps are non-decreasing.
- Only successful sends start a cooldown....
High-Level Design
Keep a map from key to the earliest time it may be sent again. On a call, compare t with that time. If allowed, update the map to t + 10 and return True; otherwise return False without touching th...