Notesreplication🌱 seedling

Write Conflict

Also: Replication Conflict · Conflict Resolution · Concurrent Write Conflict

Two replicas accept different writes to the same data without either seeing the other's. Every replica must then converge on one outcome, and someone has to decide which.

Why it exists

With one leader, a second write either waits for the first or sees it. With several leaders or leaderless replicas, both succeed locally and the clash is discovered later, asynchronously, when the users can't be asked to retry.

How it works

  • Avoid: route all writes for a record to one home leader.
  • Converge automatically: a deterministic rule every replica applies: Last Write Wins, a merge (union, concatenation), or a CRDT.
  • Keep and resolve: store all concurrent versions (siblings, detected via Version Vectors) and let application code or a person merge them, at write time or on next read.
  • Not every conflict is two writes to one field: two bookings of one room in different regions violate an invariant without touching the same row.

Trade-offs

Strategy Cost
avoid (home leader) breaks on failover; loses local-write benefit for that record
LWW silently drops concurrent writes
app-level merge complexity in every reader
CRDT metadata; can't enforce invariants

In practice

  • PostgreSQL 18 logical replication logs and counts conflicts; an update to a row last modified by another origin is simply applied, and a unique-key clash stops replication until fixed manually.

Pitfalls

  • No merge function restores an invariant like "one booking per slot". Those writes need coordination.

Recall

These cards are also in your review deck, scheduled with spaced repetition.