Transactional Outbox and Idempotent Inbox

Transactional Outbox and Idempotent Inbox A sequence diagram generated by Archify. place order BEGIN; insert order; insert outbox row; COMMIT 201 Created read unsent outbox rows publish OrderPlaced (key = orderId) mark sent OrderPlaced (maybe duplicate) BEGIN; insert inbox(msgId) or skip; apply; COMMIT commit offset Write once Relay Consume Client · request · Sequence participant Client request Order service · business logic · Sequence participant Order service business logic Orders DB · orders + outbox · Sequence participant Orders DB orders + outbox Relay · poller or CDC · Sequence participant Relay poller or CDC Kafka · topic orders · Sequence participant Kafka topic orders Consumer · billing service · Sequence participant Consumer billing service Billing DB · data + inbox · Sequence participant Billing DB data + inbox Legend request return security async trace default message

Atomic write

  • • State change and event are one local transaction
  • • No dual write to DB and broker

At-least-once

  • • The relay may publish twice after a crash
  • • Order kept per key / partition

Inbox

  • • Unique message ID makes the consumer idempotent
  • • Effect and dedup record commit together