The Ordering Problem
In a leaderless store, two replicas may each accept a write without knowing about the other. A plain timestamp cannot tell whether one write truly happened after another or whether they happened concurrently. A vector clock answers this.
How a Vector Clock Works
A vector clock is a set of counters, one per replica. When a replica processes a write it increments its own counter. The version it produces carries the whole vector. To compare two versions you compare every counter.
- If every counter in version A is at least as large as in B and at least one is strictly greater, then A descends from B and supersedes it.
- If neither dominates the other, the versions are concurrent and represent a genuine conflict.
Resolving Conflicts
When versions are concurrent the system keeps both as siblings and asks the application or a merge rule to reconcile them, for example by taking a union of a shopping cart.
Key idea
Vector clocks track a counter per replica so comparing two versions reveals whether one supersedes the other or whether they are concurrent and must be reconciled as conflicting siblings.