Dual Write

Writing a single event or piece of data to two separate storage systems without a distributed transaction, risking data drift due to partial failures where one write succeeds and the other fails.

General Meaning

Dual write refers to the pattern of updating two or more separate data stores—such as a primary database and a search index, or local files and a remote database—in response to a single application event without an atomic distributed transaction like two-phase commit. It is common in distributed systems where different storage engines serve different query needs.

The fundamental danger of dual writes is the dual-write problem, where a network failure or process crash between writes leaves one store updated and the other stale. Furthermore, when concurrent writes execute out of order across stores, data versions diverge permanently without any built-in mechanism for conflict detection or automated reconciliation.

Why It Matters

  • Preventing divergence from partial failures: When one write succeeds while the other fails, it becomes impossible to determine which storage engine holds the authoritative state.
  • Avoiding race conditions and ordering inversions: Concurrent updates can reach different data stores in conflicting orders, leading to silent state corruption.
  • Clarifying authoritative versus derived data: Enforces a clear unidirectional pipeline using an outbox pattern or event log rather than treating two separate databases as co-equal sources of truth.

How the Site Factory Uses It

In the Site Factory, deployment evidence for static sites (Direct Upload verification) is dual-recorded in both the local Git working tree (trusted-upload-evidence.json) and the Cloudflare D1 database (direct_upload_evidence table). To mitigate dual-write inconsistencies, the Site Factory establishes strict write ordering and automated publication suppression.

The pipeline writes execution intent to a local journal before dispatching data to D1; if D1 synchronization fails, it raises an EvidenceUnavailable exception and aborts publication immediately. Writes to D1 verify the node's service lease generation number and security token via compare-and-swap, while incoming nodes hydrate local state from D1 and safely quarantine conflicting local artifacts.

Caveats & Operational Rules

  • The illusion of safety in redundancy: Writing to two systems under the belief that it adds redundancy drastically increases operational complexity when recovering from partial failures.
  • Never swallow secondary write errors: Suppressing a failed write to D1 because the local Git write succeeded leaves the deployment invisible to monitoring dashboards and peer nodes.
  • Avoid duplicate sources of truth: Always define an explicit master-replica or source-of-truth relationship rather than attempting to keep two independent stores in symmetric synchronization.

Related Terms

References

  • Book: Martin Kleppmann, *Designing Data-Intensive Applications*, Chapter 11 (Stream Processing: Distributed Transactions and Dual Writes)

Verified: 2026-11-08