Vector clocks, and telling concurrent from newer
Lesson 6.06 established that wall clocks disagree and gave you logical clocks as the alternative: a counter incremented on every event, raised to the maximum seen whenever a message arrives. It guarantees that if A caused B then A's counter is lower. That is genuinely useful and it is not enough, and the gap is where a specific class of silent data loss lives.
What a single counter cannot tell you
A Lamport clock gives one number per event, so any two events can be ordered. The guarantee runs one way only: if A happened before B, then L(A) < L(B). The converse is false. Seeing L(A) < L(B) tells you nothing about whether A caused B or whether the two happened on opposite sides of the planet with no knowledge of each other.
So you can sort everything, and you cannot detect concurrency — and concurrency is precisely the situation that needs a decision. Two users editing the same document offline, two replicas accepting writes during a partition, a phone syncing changes made while it was in a tunnel: in each case the system must distinguish "this update is genuinely newer, apply it" from "these two updates conflict, and choosing one destroys the other."
One counter per writer
A vector clock keeps a counter for every node that can write. A node increments its own slot on each local event; on receiving a message it takes the element-wise maximum of its vector and the sender's, then increments its own slot again.
Comparison is now a partial order, and that is the whole point. If every element of V(A) is less than or equal to V(B), then A definitely happened before B. If neither dominates the other — each vector is ahead in some position — the two events are concurrent, and the system knows it. Detection is the deliverable.
What a system does with that knowledge is the design decision. It can keep both versions and hand them to the reader as siblings, as Dynamo-lineage stores do. It can apply a merge function. It can surface the conflict to a human, which is what version control does when it stops and asks. All three are honest. What none of them do is throw one write away and report success.
The costs, which are real
- Size grows with the number of writers. A vector across five replicas is trivial. A vector with an entry per client device, across fifty million devices, is not a data structure — it is the data. This is why systems track causality per replica rather than per client, and why refinements exist that keep the vector proportional to replicas while still attributing writes to clients.
- Retiring entries is genuinely hard. A node that leaves permanently keeps its slot forever unless something prunes it, and pruning wrongly can make two causally ordered events look concurrent — which is a correctness bug that appears months later as a conflict nobody can explain.
- Detection is not resolution. The clock tells you a conflict exists and has nothing to say about what the merged value should be. Somebody writes that logic, and it is usually the application. Lesson 8.04's conflict-free replicated data types are the response to exactly this: choose data types whose merge is defined by construction, so the question never reaches your code.
What is actually used in practice
Most systems that need ordering across a real fleet reach for a hybrid logical clock: a physical timestamp with a logical counter attached. The physical part keeps values close to wall-clock time, so they are comparable across a system and mean something to a human reading a log. The logical part is what advances when messages arrive, so causality is never violated even when the physical clocks disagree. You get timestamps that sort sensibly and a guarantee that a cause never sorts after its effect, which is the combination the pure forms each half-deliver.
Storing a wall-clock timestamp as the version and calling last-write-wins a conflict resolution strategy. It is a tie-break rule attached to a data loss policy: the write that survives is the one from whichever node's clock ran fast, so a server two hundred milliseconds ahead wins every race for two hundred milliseconds, and the losing write disappears with no error, no log line and no way to reconstruct it. Last-write-wins is frequently the right call — it is cheap, it is simple, and plenty of domains genuinely do not care. Say the second half of the sentence out loud in the design review anyway: we are accepting the silent loss of concurrent writes, and here is why this data can tolerate that. A team that has said it can live with the consequence. A team that has not will be debugging a disappearance.
Going deeper
- Timestamps in Message-Passing Systems That Preserve the Partial Ordering Colin Fidge, 1988
The short paper that introduced the vector construction and, more usefully, states precisely what property the single-counter version fails to provide.