Conflict resolution
When concurrent writes collide: last-write-wins, merges, application logic and avoiding conflicts in the first place.
16 min readWhere conflicts come from
Any system that accepts writes in more than one place without coordinating, such as multi-leader replication, leaderless stores and offline-first clients, will see two writes to the same record that neither knew about. Detecting them needs version vectors or similar metadata; a plain timestamp cannot tell concurrent from sequential. Once detected, the system needs a deterministic rule so that every replica ends with the same value. If two replicas apply different rules, or the same rule in a different order with a non-commutative result, they diverge permanently.
Last-write-wins
Last-write-wins (LWW) keeps the write with the highest timestamp and discards the rest. It is simple and converges, and it is the default in Cassandra and many multi-region stores. It also silently loses data: if two regions update a profile within the same second, one update vanishes, and clock skew can make an older write win. LWW is fine for values that are replaced wholesale and where losing a concurrent update is acceptable, such as a last-seen timestamp or a cached avatar URL.
Better merges
Resolve at a finer grain and with meaning. The more the merge knows about what the data represents, the less it has to throw away.
- Per-field LWW: a name change in one region and an email change in another both survive
- Merge functions: union of sets (tags, cart items), max of counters, sum of per-region deltas
- Keep siblings and let the application or user choose, as Riak and file-sync tools do
- CRDTs: data types whose merge is guaranteed to converge, covered next
Avoid conflicts by design
The cheapest conflict is the one that cannot happen. Give each record a home region that alone accepts its writes, and route writes there, which keeps local-latency reads everywhere and single-leader semantics per record. Make records append-only events rather than mutable fields. For invariants that cannot be merged, such as a unique username or the last hotel room, route the operation to a single authority and accept the extra latency. A rare, slow write is a far better trade than a conflict you cannot resolve.
Key takeaways
- Concurrent writes in multiple places will conflict; detect them with version vectors
- Last-write-wins converges but silently drops data and trusts clocks
- Merge per field or with semantic functions when updates must not be lost
- Avoid conflicts with per-record home regions and single authorities for invariants
Sign in to track lessons and earn badges.