Last-Write-Wins (LWW) Strategy
What You'll Learn
You'll learn how timestamps can automatically resolve replication conflicts by simply keeping whichever write happened last.
The Core Idea
When two replicas modify the same data independently (a multi-leader or leaderless scenario), you need a conflict resolution strategy. Last-Write-Wins (LWW) is the simplest: each write carries a timestamp, and during conflict detection, the system keeps the write with the most recent timestamp and discards the others.
Think of it like two people editing a shared document offline. When they reconnect, instead of merging their changes, you simply ask: "Who saved last?" That version wins, and the earlier one is lost.
How It Works
- Every write operation is tagged with a timestamp (wall-clock time or logical clock)
- When a conflict is detected between versions, compare timestamps
- The write with the higher (later) timestamp is kept
- All conflicting earlier writes are discarded
The Good and The Bad
Advantages:
- Dead simple to implement
- Deterministic: all replicas converge to the same value
- No human intervention needed
Disadvantages:
- Data loss is guaranteed — earlier writes disappear completely
- Clock synchronization problems can cause unexpected "winners"
- No semantic understanding of what was actually changed
- Users get no warning that their work was discarded
LWW works well for cases where data is naturally overwriting (like "current temperature" or "user status"), but poorly for collaborative scenarios where every edit matters.
Key Takeaway:
Last-Write-Wins resolves conflicts automatically using timestamps, prioritizing simplicity and convergence over preserving all user data — making it ideal for use cases where losing occasional writes is acceptable.