An outbox relay should retry transient publication failures without retrying forever. After a configured number of failed delivery attempts, a poison event moves to a dead-letter state so later events and operators can make progress.
Design an OutboxRetryScheduler class:
OutboxRetryScheduler(int maxAttempts, int baseDelaySeconds) configures one retry policy.String recordFailure(int sequence) records a failed delivery attempt.String recordSuccess(int sequence) records successful publication.int failures(int sequence) returns the stored failure count, or 0 for an unseen event.
For the f-th failure of a nonterminal event:
- If
f < maxAttempts, return "RETRY:d", where d = baseDelaySeconds * 2^(f - 1). - If
f == maxAttempts, mark the event terminal and return "DEAD_LETTER".
recordSuccess marks any non-dead-lettered event "PUBLISHED". Both PUBLISHED and DEAD_LETTER are terminal: every later success or failure call returns the stored terminal string and does not change the failure count.
Example 1:
Input:
Output:
Explanation: The first two failures schedule exponential delays. The third reaches the cap, and subsequent calls cannot leave the dead-letter state.
Example 2:
Input:
Output:
Explanation: Success makes the event terminal with its one historical failure preserved.
Constraints
1 <= maxAttempts <= 201 <= baseDelaySeconds <= 10000 <= sequence <= 10^9- All computed retry delays fit in a signed 32-bit integer.
- At most
1000 method calls are made per object.