The Problem of Concurrent Writes
In a system that accepts writes on multiple replicas, two clients can update the same key at the same time. The system must decide whether one write happened before the other or whether they are truly concurrent and conflict. Wall clock timestamps are unreliable across machines, so something better is needed.
What a Vector Clock Is
A vector clock is a list of counters, one per replica. Each time a replica processes a write, it increments its own counter. The vector attached to a value records how much history from each replica that value has seen.
Comparing Versions
- If every counter in vector A is greater than or equal to vector B, then A descends from B and is newer.
- If neither dominates the other, the two versions are concurrent and represent a conflict.
- Concurrent versions are kept as siblings for the application or a merge function to resolve.
Why Not Just Last Write Wins
Last write wins silently discards one update. Vector clocks instead detect the conflict so it can be merged intelligently, for example by unioning two shopping carts rather than dropping one.
Key idea
Vector clocks track per replica causal history to distinguish ordered updates from concurrent conflicts, enabling intelligent merges instead of silent data loss.