liveBook · Manning

Dual-write mode

As explained in Grokking Software Architecture

A dual write is an operation that updates two separate systems, such as a database and a message broker, without a shared atomic commit.

A dual write updates two destinations as part of one operation. When those destinations are separate systems without a shared atomic commit, one update can succeed while the other fails. The result is a split-brain receipt: one system says the work happened, while the other never heard about it. section 12.5.2 section 7.5.1

An order gets lost in transit

An order service saves an order to its database and publishes an OrderPlaced event to a broker. If the save succeeds but the network drops before publication, shipping and payment workers are not notified. Reversing the order is no cure: publishing first can announce an order whose database save then fails. section 7.5.1

The same trap appears when migrating from a legacy database to a microservice database. Writing to both is initially easy, but a network failure between the writes can leave them out of sync. Change Data Capture (CDC) is an alternative for synchronizing changes from database logs; it needs a snapshot for historical data because old logs may already have been purged. section 12.5.2

When database logs are unavailable, the Transactional Outbox provides an application-level alternative. Rather than trying to commit a local update and a remote operation together, it records the database change and an outgoing message in one local transaction. This avoids treating a network call as part of that atomic commit. section 12.5.2 section 7.5.1

Dual writes during a schema transition

Dual-write mode can also mean writing both old and new layouts within a database. During an Expand/Contract migration, code can keep reading customer_phone while writing both customer_phone and phone_mobile; a background process backfills older records. Use deterministic write ordering or optimistic concurrency locks so an older service instance cannot overwrite a migrated value. Remove the old column only after all instances have transitioned and backfill is complete. section 13.4.3

INSERT INTO orders (id, customer_phone, phone_mobile) VALUES (101, '555-0199', '555-0199');

This insert writes the same phone value to both columns during the transition. section 13.4.3

Check what “dual write” means in context. Separate systems can diverge when a network operation fails; two layouts in one database can still suffer conflicting writes from old and new service versions. section 12.5.2 section 13.4.3

How Grokking Software Architecture covers it

How deep it goes
Defines cross-system dual writes and walks through partial failures and alternatives, without a full outbox implementation.
Examples
Uses order publication, legacy-to-microservice database synchronization, and a phone-column rename to illustrate dual-write scenarios.
What you can do after
Evaluate dual-write failure risks and distinguish migration alternatives from safeguards for a schema-transition window.
How it connects
Connects dual writes to Change Data Capture, Transactional Outbox, and Expand/Contract.

Also explained in

Compare how 2 books explain dual-write mode →

Related concepts

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