Last-Write-Wins (LWW) Conflict Resolution
You'll learn: How distributed systems use timestamps to automatically resolve conflicting writes by keeping whichever update happened most recently.
The Core Idea
When multiple replicas accept writes to the same data item, conflicts arise. Last-Write-Wins (LWW) is the simplest conflict resolution strategy: attach a timestamp to every write, and when a conflict is detected, keep the write with the highest (most recent) timestamp and discard all others.
Think of it like a whiteboard where multiple people can write simultaneously. When two people write different things in the same spot, LWW says "whoever wrote last wins" — their message stays, the earlier one disappears.
How It Works
Each write operation includes a timestamp (physical clock, Lamport timestamp, or other ordering mechanism). When the system detects conflicting versions during read repair or anti-entropy, it compares timestamps:
- Conflict detected: Two replicas have different values for key
user:123:email - Replica A:
"alice@old.com"(timestamp: 1000) - Replica B:
"alice@new.com"(timestamp: 1005) - Resolution: Keep
"alice@new.com", discard the older value
Critical Limitations
Data loss is inevitable with LWW. If two concurrent writes happen with slightly different timestamps due to clock skew, one write completely disappears — even if both were valid updates. Users might see their changes vanish without warning.
LWW also doesn't respect causality: a write with timestamp 1001 might actually have happened before a write with timestamp 1000 if clocks differ between nodes.
Key Takeaway: Last-Write-Wins provides automatic conflict resolution using timestamps, but sacrifices data durability — concurrent writes are silently lost, making it suitable only when occasional data loss is acceptable.