Skip to main content

Transactional Outbox

Challenge on lesson: Checkpoint: Persistence

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.

Difficulty: intermediate

Back to lesson: Checkpoint: Persistence