Order events across processes with no shared clock — and tell true causality apart from mere coincidence.
In a distributed system there is no single trustworthy clock, so you can't order events by timestamp. Vector clocks order them by *causality* instead — by whether one event could actually have influenced another. Each process keeps a vector of counters, one slot per process, that records how many events it knows about from everyone.
i keeps a vector V of length n (one entry per process), starting all zeros.i increments its own entry, V[i] += 1.V[i], then attach a copy of V to the message.V[i].The element-wise max on receive is the key move: the receiver inherits everything the sender already knew, so its vector now reflects the full causal history flowing into that point.
Compare two event vectors V and W entry by entry. V happened-before W when every entry of V is ≤ the matching entry of W and at least one is strictly less. If neither happened-before the other, the events are concurrent — independent, with no cause-and-effect between them.
P1 local e1 -> [1,0,0]
P2 local e2 -> [0,1,0]
P1 sends msg (send) -> [2,0,0] attaches [2,0,0]
P2 receives msg -> max([0,1,0],[2,0,0]) = [2,1,0], +1 own = [2,2,0]
e1 [1,0,0] vs recv [2,2,0]: every entry <=, one strictly < -> e1 happened-before
e2 [0,1,0] vs send [2,0,0]: neither <= the other -> concurrent