Logger Rate Limiter
On this page
Problem statement
Design a logger that receives a stream of
(timestamp, message)calls in non-decreasing time order.should_print(timestamp, message)returnsTrueif the message should be printed, andFalseif the same message was printed less than 10 seconds ago. A message printed at time t blocks repeats until time t + 10, when it may print again. Rejected calls don't count as printed.
A small design question, often the warm-up before a rate-limiting discussion. The core is a few lines; the follow-ups (memory, many threads, many servers) are where the interview goes next. Original problem: LeetCode 359.
Example

should_print(1, "disk full") -> True
should_print(2, "login failed") -> True
should_print(3, "disk full") -> False # printed at 1, too soon
should_print(8, "login failed") -> False
should_print(11, "disk full") -> True # 11 - 1 = 10, allowed again
should_print(11, "disk full") -> False # just printed at 11
should_print(12, "login failed") -> True
Constraints (assumed)
- Timestamps are integers in seconds and never decrease.
- Up to 10⁴ calls; messages are short strings.
What this question tests
- Picking the right state to store: the next allowed time per message.
- Getting the boundary right (exactly 10 seconds later is allowed).
- Knowing what not to update on a rejected call.
Questions to ask first
- Is exactly 10 seconds later allowed? (Here: yes.)
- Do rejected calls reset the window? (Here: no.)
- Are timestamps in order? (Here: yes. Out-of-order input is a follow-up.)
- How many distinct messages? If unbounded, memory needs cleanup.
- Single-threaded? (Here: yes.)
Try it yourself first
You have the full problem. Sketch your answer, then sign up free to read the complete walkthrough.
- The complete design, flow by flow, with pictures
- Deep dives into the hard parts
- What mid, senior and staff candidates are expected to say
- Full company question lists
Free forever. No card needed.