Why wall clocks fail
In a distributed system you cannot trust wall clock time to order events, because clocks drift and messages cross at odd moments. A vector clock captures causality instead: which event truly happened before which.
How it works
Each node keeps a vector with one counter per node. The rules are simple:
- Before a local event, a node increments its own counter.
- When sending a message it attaches its whole vector.
- On receiving, a node takes the element wise maximum of its vector and the incoming one, then increments its own counter.
Comparing two vectors
Given two vectors X and Y:
- If every entry of X is less than or equal to Y and at least one is strictly less, then X happened before Y.
- If neither dominates the other, the events are concurrent, which usually signals a conflict.
Systems use this to detect conflicting writes that need merging rather than blindly picking the latest. The cost is that the vector grows with the number of nodes, so large clusters prune or cap entries.
Key idea
Vector clocks track causality so a system can tell ordered updates apart from genuinely concurrent ones.