The transactional outbox pattern stores an event in the same database transaction as the business update. A relay later reads those rows and publishes them to a broker. To resume after a restart, the relay can use the sequence number of the last confirmed event as a checkpoint.
Design an OutboxRelay class:
OutboxRelay() creates a stateless relay helper.int[] pendingEvents(int[] eventSequences, int lastPublished) returns the sequence numbers that should be published next.eventSequences contains the distinct sequence numbers in the current outbox snapshot. The snapshot may be in any order and may contain gaps. lastPublished is the sequence number of the last event whose publication was confirmed.
Return every sequence number strictly greater than lastPublished, sorted in ascending order. Events at or before the checkpoint have already been handled.
Input:
Output:
Explanation: Events 1 and 2 are covered by the checkpoint. The relay publishes 3, 4, and 5 in sequence order.
Input:
Output:
Explanation: Sequence 3 is already published. The remaining rows are returned in ascending order even though the snapshot is unordered.
0 <= eventSequences.length <= 2000 <= eventSequences[i] <= 10^9eventSequences are distinct.-1 <= lastPublished <= 10^9100 calls are made to pendingEvents per object, and calls are independent.| Call | Returns |
|---|---|
| new OutboxRelay() | null |
| pendingEvents([1,2,3,4,5], 2) | [3,4,5] |
Sequences 1 and 2 are at or before the checkpoint; 3, 4, and 5 are pending in publication order.
Run checks these cases. Submit also runs a larger hidden set.

