Conflict Detection Mechanisms
You'll learn: How distributed systems identify when concurrent writes have created conflicting versions of the same data.
The Challenge of Seeing Conflicts
When multiple replicas accept writes independently (as in multi-leader or leaderless replication), conflicts are inevitable. But before you can resolve a conflict, you must detect it. The system needs a way to ask: "Did two nodes update the same data independently, creating diverging histories?"
Detection sounds simple but isn't—especially when writes happen across geographic regions with network delays. You can't rely on wall-clock timestamps because server clocks drift and skew.
Three Core Detection Approaches
Version Vectors (Vector Clocks)
Each replica maintains a counter for every node in the system. When a write occurs, the local counter increments. By comparing version vectors, you can determine if writes are concurrent (conflict) or if one happened-before another (no conflict). Think of it as each replica keeping a "scorecard" showing what it knows from every other replica.
Example: Node A has {A:3, B:1}, Node B has {A:2, B:2}. Neither vector fully dominates the other—conflict detected.
Timestamps
Some systems use Lamport timestamps or physical timestamps to order events. If two writes have timestamps that can't establish clear causality, they conflict. Simpler than vectors but less accurate.
Logical Clocks
Systems like Cassandra use logical clocks to track causality. These provide ordering guarantees without full vector overhead—useful when you need "good enough" conflict detection at scale.
Key Takeaway: Conflict detection mechanisms like version vectors, timestamps, and logical clocks allow distributed systems to identify when concurrent writes have created diverging data states that require resolution.