← Lessons

quiz vs the machine

Gold1470

Databases

Vector Clocks For Causality

A per node counter set that captures which updates happened before which, so replicas can tell true conflicts from stale overwrites.

5 min read · core · beat Gold to climb

Ordering Without a Global Clock

Wall clocks across nodes drift, so they cannot reliably order events. A vector clock tracks causality instead. Each node keeps a counter for every node in the system. On a local event a node increments its own counter, and when it receives a message it takes the element wise maximum of the two vectors.

Reading the Vectors

Compare two vectors element by element.

  • If every element 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 they have no causal order.

Why This Helps Replicas

When two replicas disagree on a value, vector clocks reveal whether one update causally followed the other or whether they happened independently.

  • A causally later version simply supersedes the earlier one.
  • Two concurrent versions are a genuine conflict that must be merged or surfaced to the application, never silently dropped.

This prevents a slow path update from being lost to a stale write that only looked newer by timestamp.

Key idea

Vector clocks track per node counters so replicas can tell causally ordered updates from concurrent conflicts, keeping real conflicts from being silently lost.

Check yourself

Answer to earn rating on the learn ladder.

1. What does a vector clock record?

2. When are two versions considered concurrent under vector clocks?

3. Why are concurrent versions important to detect?