liveBook · Manning

Dual-write problem

As explained in Clean Applications with Hexagonal Architecture

The dual-write problem is the consistency failure that occurs when one operation must atomically update a database and publish a message through separate systems.

When a handler commits business state and publishes directly to a broker, either write can succeed alone: an article may be published without an event, or an event may describe a rolled-back article. section 6.5.3 section 9.5.2

The transactional outbox closes this gap by recording the event intent in the same database transaction as the business change. A rollback removes both writes; a commit preserves both. A separate relay forwards pending events, with at-least-once delivery, so consumers must handle duplicates idempotently. section 6.5.3 section 9.5.2

Publishing an article

When an article becomes published, its integration event is stored in the outbox alongside that state change. A consumer can use the event ID to recognize and skip duplicate deliveries. section 6.5.3 section 9.5.2

Figure 6.5 From handler to external delivery. The handler calls an output port whose adapter writes the integration event to the outbox within the same transaction. A relay process delivers it to external consumers. Consistency is guaranteed because the outbox write shares the domain state's transaction.

Trace the handler-to-outbox transaction and the relay to external consumers. section 6.5.3

How Clean Applications with Hexagonal Architecture covers it

How deep it goes
Explains atomic outbox writes and at-least-once relay delivery, while leaving relay implementation outside the detailed implementation.
Examples
Uses article publication, an outbox table, and event-ID checks to illustrate the failure and duplicate-delivery cases.
What you can do after
Apply the transactional outbox by storing event intent with business state and designing consumers to tolerate duplicate delivery.
How it connects
Connects database transactions, integration events, domain events, and consumer idempotency.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clean Applications with Hexagonal Architecture. The section links point to the parts of the book it draws on.