One counter per machine, so you can tell if two events were related or happened at the same time.
A vector clock is a small list of counters, one for each machine. It lets a distributed system tell whether one event happened before another, or whether the two were concurrent (they happened independently).
In a distributed system we cannot trust wall clocks, because every machine's clock is a little different. So we ask a better question: could event A have influenced event B? If A happened, then a message chain carried the news to B, then A "happened before" B. If there is no such chain, the two events are concurrent.
A Lamport timestamp is a single number. If A happened before B, A's number is smaller. But the reverse is not true: a smaller number does not prove that A happened before B. The two might simply be unrelated. That is the gap vector clocks close.
A vector clock keeps one counter per process. Process B's vector [1, 3, 0] means: "I have seen 1 event from A, 3 events from myself, and 0 from C." The rules are short:
| Lamport timestamp | Vector clock | |
|---|---|---|
| Size | One number | One number per process |
| If A happened before B | L(A) < L(B) | V(A) < V(B) |
| If L(A) < L(B) or V(A) < V(B) | Cannot say that A happened before B | A did happen before B |
| Detects concurrent events | No | Yes |
| Cost | Tiny | Grows with the number of processes |
| Good for | A simple total order, such as a log | Conflict detection, version tracking |
Rules used: before every event a process adds 1 to its own slot. When a message arrives, the receiver first takes the slot-by-slot maximum of its own vector and the one in the message. Try c1 and a2: Lamport gives 1 and 2, so it looks ordered, but the vectors show they are concurrent.
| Term | Meaning in easy words |
|---|---|
| Vector clock | A list of counters, one per process, used to order events and spot concurrent ones |
| Happened-before (โ) | A is before B if A could have influenced B through a chain of messages or the same process order |
| Concurrent | Neither event could have influenced the other |
| Causality | The link between a cause and its effect, as carried by messages |
| Lamport timestamp | A single logical counter that respects happened-before in one direction only |
| Merge (max) | Slot-by-slot maximum of two vectors, done when a message is received |
| Sibling | One of several concurrent versions of the same value that a store keeps |
| Version vector | A vector clock attached to a data item to track its versions across replicas |
| Last-write-wins | A simple rule where the newest wall-clock time wins. It can lose data |
| Conflict resolution | Deciding what to do with concurrent writes: merge, pick one or ask the user |
| Hybrid logical clock | A clock that mixes physical time and a counter, with a fixed size |
| Choice | We gain | We lose |
|---|---|---|
| Vector clocks | Conflicts are visible and no write is lost | Bigger metadata and siblings to resolve |
| Lamport timestamps | One small number, a total order | Cannot tell concurrent from ordered |
| Last-write-wins (wall clock) | Simplest to build, no siblings | Silently drops one of two concurrent writes |
| Single leader + version number | No concurrency to worry about | The leader is a bottleneck and a single point of failure |
| Hybrid logical clocks | Fixed size and close to real time | Cannot detect concurrent writes by themselves |