outbox-demo · sequence diagram

Scenario D · Temporary broker failure

Kafka fails twice. The relay records each attempt and publishes on the third run.

1 transaction 1 transaction Mainscenarios OrderServicecreateOrder() OutboxRelaypublishPendingEvents() FakeDatabasesimulated DB FakeKafkaorders.events PaymentConsumerhandle(offset) createOrder("Dave") INSERT orders + outbox (NEW) COMMIT orderId setFailuresToSimulate(2) Relay run 1 publishPendingEvents() SELECT pending 1 event (NEW) UPDATE status=PROCESSING send(key=orderId, eventId) RuntimeException: Broker unavailable UPDATE FAILED, attempts=1 attempts=1 retry on next run (1 of 3) Relay run 2 publishPendingEvents() SELECT pending 1 event (FAILED) UPDATE status=PROCESSING send(key=orderId, eventId) RuntimeException: Broker unavailable UPDATE FAILED, attempts=2 attempts=2 retry on next run (2 of 3) Relay run 3: Kafka is back publishPendingEvents() SELECT pending 1 event (FAILED) UPDATE status=PROCESSING send(key=orderId, eventId) offset 4 UPDATE status=SENT The consumer processes handle(4) read(4) record(key, eventId) BEGIN TRANSACTION INSERT processed_events true (new) INSERT payments (PENDING) COMMIT commit offset 4 Result: FAILED → FAILED → SENT, 1 payment for Dave
Solid arrows: calls. Dashed: replies. Red: errors and crashes. Dashed blue boxes: database transactions; amber: the duplicate branch.

What to look for