Dashboard
Courses
Problems
Badges
Theme
Sign inStart free
Courses/Distributed Architecture
Lesson 19 of 24

Conflict resolution

When concurrent writes collide: last-write-wins, merges, application logic and avoiding conflicts in the first place.

16 min read

Where 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.

Caching in distributed systemsCRDTs and operational transformation

Coming up

Course: 0/24 lessons · 0/10 challenges0%

Build it on the canvas, pass the review (70+) and mark it complete to count it toward the course badge.

  1. 8/10Design a Collaborative Document EditorApply CRDTs or OT, per-document session routing and a durable operation log to make concurrent edits converge.MAJORHardPRO
  • 9/10Design a Multi-Region Active-Active StoreRun writable profiles in three regions with replication, conflict resolution, failover headroom and global traffic routing.MAJORHardPRO
  • All 10 challenges →