Systems & Backend

Vector Clock

also: logical clock · Lamport clock

Counters that capture causality — decide whether two events are ordered or truly concurrent.

Wall clocks lie across machines, so distributed systems track causality instead: each node keeps a counter per node, increments its own on events, and merges on communication. Comparing vectors tells you A happened-before B, or they are concurrent — genuine conflicts needing resolution. Dynamo-style stores used them to detect conflicting writes; simpler Lamport clocks give total order without concurrency detection.

Worked example: a distributed clock: each node keeps a counter per node, increments its own on each event, and attaches the whole vector to messages, so two events can be compared as before/after or concurrent without a global clock. Gotcha: vector clocks DETECT concurrent updates (conflicts) but do not resolve them — that is left to the application (last-write-wins, merge, or ask the user) — and the vector grows with the node count, so large dynamic clusters need pruning or dotted version vectors.