Back to roadmap
Module 3 · Consistency & ReplicationDay 02625 min

Conflict Resolution

When concurrent writes diverge, you need a deterministic merge.

Day 026

Conflict Resolution

LWW
note
Vector clocks
note
CRDT
note
Memory hook

Conflict Resolution: when concurrent writes diverge, you need a deterministic merge

Mental model

choose the failure mode you can explain

Design lens

CRDTs add metadata overhead.

Recall anchors
LWWVector clocksCRDT

Why it matters

In multi-leader and leaderless systems, concurrent writes can produce conflicting values. Strategies range from last-writer-wins (simple, lossy) to vector clocks (precise, complex) to CRDTs (commutative data structures that merge automatically).

Deep dive

LWW: pick the highest timestamp; loses one update silently. Acceptable for cosmetic state.

Vector clocks: detect concurrent updates and let app merge; correct, more code.

CRDTs: counters, sets, sequences with built-in commutative merge — collaborative editing leans on these.

Demo / scenario

Shopping cart edited offline on two devices.

  1. Device A: add item X.
  2. Device B: add item Y while offline.
  3. Sync: LWW would lose one; cart should keep both.
  4. Use OR-set CRDT — both adds merge automatically.

Tradeoffs

  • CRDTs add metadata overhead.
  • LWW loses data but is trivial.
  • App-level merge is most flexible but error-prone.

Diagram

LWW
Vector clocks
CRDT
Three strategies for diverged writes.

Mind map

Check yourself

Loading quiz…

Sources & further reading