Course contentsShow
← Computer Science
Lesson 2633 of 2,87258. Distributed Systems BasicsFree lesson

Detecting Causality with Vector Clocks

Using vector clock comparisons to identify happens-before, concurrent, or independent events.

Detecting Causality with Vector Clocks

You'll learn: How to use vector clock comparisons to determine whether events are causally related, concurrent, or independent in a distributed system.

The Core Idea

Vector clocks assign each event a timestamp that's actually a vector (array) of clock values—one per node in the system. By comparing these vectors, we can definitively answer: "Did event A cause event B, or could they have happened independently?"

The comparison rules are straightforward:

Happens-Before (A → B): Vector clock VC(A) ≤ VC(B) and VC(A) ≠ VC(B). This means every component in A's vector is less than or equal to B's, with at least one being strictly less. Event A causally preceded B.

Concurrent (A || B): Neither vector is less than or equal to the other. Some components of A are greater than B's, while others are smaller. These events happened independently—neither caused the other.

Independent/Equal: VC(A) = VC(B) only when they're literally the same event.

Analogy: Progress Reports

Imagine three teams filing progress reports. Team 1's report [5, 2, 1] means: "We've done 5 tasks, and we know Team 2 has done at least 2, Team 3 at least 1." Team 2's report [5, 3, 1] shows they're ahead on their own work. Since [5, 2, 1] ≤ [5, 3, 1], Team 1's report happened-before Team 2's.

But if Team 3 reports [4, 2, 2], neither report dominates—some numbers are higher, some lower. These reports are concurrent; neither team's work caused the other's.

Why This Matters

This causal detection is crucial for maintaining consistency without global coordination, resolving conflicts in replicated data, and debugging distributed systems.

Key Takeaway: Vector clock comparison reveals causality: if one vector dominates another (all components ≤, at least one <), there's a happens-before relationship; otherwise, events are concurrent.