Sobes.tech
Senior

Have you heard of the Transactional Outbox Pattern?

sobes.tech AI

Answer from AI

Transactional Outbox Pattern is an integration pattern that helps guarantee the atomicity of writing business data and messages to external systems in distributed applications.

The idea is that during a business operation within a single database transaction, an event (message) is simultaneously written to a special table — the "outbox". After the transaction commits successfully, a separate process or service reads these messages from the table and sends them to a queue or external system.

This solves the "two-phase commit" problem between the database and the messaging system, ensuring reliable delivery of events without loss or duplication.

Example:

  1. Changes are saved in business tables and a record is added to the outbox table within a transaction.
  2. The transaction commits.
  3. A separate worker periodically reads new records from the outbox and publishes them to a message broker.
  4. After successful publication, the record from the outbox is deleted or marked as processed.