Skip to main content

Transactional Outbox

Challenge on lesson: Checkpoint: Persistence

CHALLENGE
Difficulty: intermediate+25 XP

An outbox records pending side effects atomically with data changes. Implement in Solution: - record OutboxEntry(String id, String topic, String payload) - static class OutboxStore: - boolean offer(OutboxEntry e) โ€” appends if the id is new, returns true; duplicate id returns false (idempotent producer). - List<OutboxEntry> drain(String topic) โ€” removes and returns ALL entries for that topic in insertion order. - int pending() โ€” total across topics. - static int deliverAll(OutboxStore store, String topic, java.util.function.Consumer<OutboxEntry> sink) โ€” drains the topic, feeding each entry to sink, returning the count delivered. The transactional property under test: an entry is delivered exactly once even if offer() was called multiple times.

Back to lesson: Checkpoint: Persistence