Why it matters

Without causality tracking, distributed systems can't resolve conflicts intelligently. Vector clocks make it possible to know which write superseded which, or which are truly concurrent.

Advertisement

The architecture

Each node maintains a vector [c1, c2, c3, ...] with one counter per node. Initially all zero.

On local event: increment own counter. On send: include current vector in message. On receive: for each position, take max of local and message, then increment own counter.

Vector clock operationsLocal eventincrement ownSend msgattach vectorReceive msgmerge (max)Comparing vectors reveals happened-before (A before B iff A <= B and A != B); else concurrent
Vector clock updates.
Advertisement

How it works end to end

Comparison: vector A happened before vector B if every counter in A is less than or equal to the corresponding counter in B, and at least one is strictly less. Otherwise concurrent.

Version vectors: a variant used for objects. Each replica of an object has its version vector; conflicts detected via vector comparison.

Dotted version vectors: more compact for many concurrent writers. Used by modern Dynamo-style stores.