outbox-demo · sequence diagram

Scenario C · Consumer crash

The consumer commits to the database and crashes before committing the offset. Kafka redelivers the message and the consumer skips it.

1 transaction 1 transaction alt · duplicate Mainscenarios OrderServicecreateOrder() OutboxRelaypublishPendingEvents() FakeDatabasesimulated DB FakeKafkaorders.events PaymentConsumerhandle(offset) createOrder("Carol") INSERT orders + outbox (NEW) COMMIT orderId The relay publishes publishPendingEvents() SELECT pending 1 event (NEW) UPDATE status=PROCESSING send(key=orderId, eventId) offset 3 UPDATE status=SENT First delivery: DB commit, then crash setSimulateCrashBeforeOffsetCommit(true) handle(3) read(3) record(key, eventId) BEGIN TRANSACTION INSERT processed_events true (new) INSERT payments (PENDING) COMMIT CRASH before offset commit RuntimeException: Simulated consumer crash offset 3 not committed Kafka redelivers offset 3 setSimulateCrashBeforeOffsetCommit(false) handle(3) read(3) same eventId BEGIN TRANSACTION INSERT processed_events false: duplicate key ROLLBACK commit offset 3 SKIP: no payment created Result: 1 payment for Carol, no second payment
Solid arrows: calls. Dashed: replies. Red: errors and crashes. Dashed blue boxes: database transactions; amber: the duplicate branch.

What to look for