At-least-once delivery can replay the same event. A stream processor commonly remembers recently accepted event IDs and expires that state after a time-to-live period.
Design an EventDeduplicator class:
EventDeduplicator(int ttlSeconds) creates an empty deduplication store.boolean accept(String eventId, int processingTime) returns whether this occurrence should be processed.
If an ID was last accepted at time t, reject it while processingTime < t + ttlSeconds. Accept it at or after the expiry boundary and replace its stored time. A rejected occurrence must not refresh the TTL. Calls use nondecreasing processing times, and IDs are case-sensitive.
Example 1:
The first a expires at time 10. Its accepted occurrence at 10 starts a new TTL, which blocks time 15.
Example 2:
The rejected calls at time 6 do not refresh state, so x becomes eligible at time 7.
Constraints
1 <= ttlSeconds <= 10^91 <= eventId.length <= 500 <= processingTime <= 10^9- Processing times are nondecreasing for one object.
- At most
10^4 calls are made to accept.