Knowing what happened before what
In a distributed system there is no single clock to order events. A vector clock gives each event a vector of counters, one per node, that captures causal history. Comparing two vectors tells you whether one event happened before another or whether they are concurrent.
How it updates
- On a local event, a node increments its own entry.
- When sending a message, it attaches its current vector.
- On receiving, the node takes the element wise maximum of its vector and the message vector, then increments its own entry.
This way a vector records every event known to have causally preceded the current one.
Comparing two vectors
Given vectors A and B, compare them element by element.
- If every entry of A is less than or equal to B and at least one is strictly less, then A happened before B.
- If neither dominates the other, the events are concurrent, meaning neither could have caused the other.
Concurrency is the important signal. Concurrent updates to the same key are a genuine conflict the application must resolve.
Key idea
A vector clock records per node counters so comparing two vectors reveals whether events are causally ordered or concurrent, and concurrent updates flag conflicts the application must resolve.