outbox-demo · sequence diagram

Scenario A · Normal flow

The order and its event are saved together, the relay publishes once, and the consumer creates one payment.

1 transaction 1 transaction Mainscenarios OrderServicecreateOrder() OutboxRelaypublishPendingEvents() FakeDatabasesimulated DB FakeKafkaorders.events PaymentConsumerhandle(offset) createOrder("Alice") BEGIN TRANSACTION INSERT orders (ORD-…, Alice) INSERT outbox (EVT-…, NEW) COMMIT orderId The relay publishes publishPendingEvents() SELECT pending 1 event (NEW) UPDATE status=PROCESSING send(key=orderId, eventId) offset 0 UPDATE status=SENT The consumer processes handle(0) read(0) record(key, eventId) BEGIN TRANSACTION INSERT processed_events true (new) INSERT payments (PENDING) COMMIT commit offset 0 Result: 1 payment for Alice
Solid arrows: calls. Dashed: replies. Red: errors and crashes. Dashed blue boxes: database transactions; amber: the duplicate branch.

What to look for