Vector clock
A list of counters, one per node, attached to each change so a system can tell whether one change happened before another or both happened concurrently.
Wall clocks on different servers drift, so timestamps cannot reliably order events across machines. Leslie Lamport’s 1978 paper on logical clocks replaced time with counters that respect cause and effect. A vector clock extends this: each node keeps a counter for every node, increments its own on each change and merges the others when it receives a message.
Comparing two vector clocks gives one of three answers: A happened before B, B before A, or they are concurrent, meaning neither saw the other. That last answer is the valuable one, because it detects a real conflict instead of letting the later timestamp silently win. Amazon’s Dynamo used vector clocks to keep conflicting versions of a shopping cart for the application to merge, and they underpin many CRDTs and sync protocols.
The cost is size: the clock grows with the number of nodes or clients that ever wrote, so systems prune old entries or use variants such as version vectors.
Sources
- Communications of the ACM: Lamport, Time, Clocks, and the Ordering of Events in a Distributed System (1978) doi.org
- Amazon (SOSP 2007): Dynamo: Amazon’s Highly Available Key-value Store allthingsdistributed.com
Related terms
- CRDT (conflict-free replicated data type): A data type that several copies can edit independently, even offline, and that always merges to the same result without a central server deciding.
- Message ordering: Whether a queue delivers messages in the order they were sent; usually guaranteed only per key or partition, if at all.
- Split-brain: Two parts of a system both believe they hold the truth and accept changes independently, so their data drifts apart.
- Eventual consistency: A guarantee that copies of data will agree once updates stop arriving, but may briefly show different values in the meantime.
- Consistent hashing: A way to spread keys across servers so that adding or removing a server moves only a small share of keys instead of nearly all of them.
