Conflict Detection in Eventual Consistency
What You'll Learn
You'll learn how to identify when concurrent updates to replicas create conflicts that need resolution in eventually consistent systems.
The Core Problem
In eventually consistent systems (like those following the BASE model), replicas accept writes independently without coordinating first. This means two clients can simultaneously update different replicas of the same data, creating conflicting versions that must later be reconciled.
Think of it like two people editing the same shared document offline. When they reconnect, the system must detect that both made changes—but which version should win?
How Conflicts Arise
Conflicts occur when:
- Concurrent writes happen to different replicas before they've synchronized
- The updates modify the same logical data item
- Network partitions prevent immediate coordination
For example:
- Replica A receives:
balance = 100 - 50 = 50 - Replica B receives:
balance = 100 - 30 = 70 - When replicas sync, which balance is correct?
Detection Mechanisms
Systems detect conflicts using:
Version vectors or vector clocks: Track causality between updates. If two versions have incomparable vector clocks (neither happened-before the other), they're concurrent and conflicting.
Last-write-wins timestamps: Compare timestamps to identify concurrent writes, though this doesn't fully detect semantic conflicts.
Semantic comparison: Application-level logic examines whether updates actually conflict (e.g., modifying different fields may not conflict).
The key insight: detection precedes resolution. You must first identify that replicas diverged before applying strategies like last-write-wins, merge functions, or client-side resolution.
Key Takeaway: Conflict detection in eventual consistency identifies when replicas have concurrent, incompatible updates by tracking causality and version history, enabling the system to apply appropriate resolution strategies.