Vector Clock

A vector clock is a refinement of Leslie Lamport’s logical clock that fixes a key limitation: a plain logical clock can order events but cannot tell you whether one event actually influenced another or whether they were unrelated. A vector clock can.

Instead of a single counter, each process keeps a vector of counters with one entry per process in the system. A process increments its own entry on each event, attaches its whole vector to outgoing messages, and on receiving a message takes the element-by-element maximum of its own vector and the received one before incrementing again. Comparing two vectors then reveals their relationship: if every entry of one is less than or equal to the other, the first event happened before the second; if neither dominates, the two events are concurrent. Friedemann Mattern’s 1989 paper “Virtual Time and Global States of Distributed Systems” develops this vector-of-clocks model and shows that such timestamps form a partially ordered lattice.

Because vector clocks can distinguish causally ordered events from concurrent ones, they are widely used wherever a system must detect and resolve conflicting updates. Amazon’s Dynamo storage system, for example, used vector clocks to recognize when two replicas had been updated independently and needed reconciliation, and similar versioning schemes appear in distributed databases and collaborative editing tools.

The main cost of vector clocks is size. Because each timestamp grows with the number of participating processes, large or rapidly changing systems sometimes use compressed or pruned variants, but the underlying idea of tracking causality per process remains the same.