A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Vector Clocks and Capturing Causality

Research Depth 95 in the knowledge graph ☐ I know this ☆ Set as goal
30topics build on this
358prerequisites beneath it
See this on the map →
Logical Clocks and Event Ordering→→Happened-Before Relation and Causal OrderingHybrid Logical Clocks
vector-clocks causality ordering

Core Idea

Vector clocks extend logical clocks with a vector of integers (one per process). Each process increments its own entry on local events and sets each entry to the maximum of its value and the sender's on message receipt. Vector clocks precisely capture causality: event A happened-before B iff A's vector is less than B's element-wise, and concurrent events have incomparable vectors.

How It's Best Learned

Implement vector clock logic and trace scenarios with concurrent writes and message chains.

Common Misconceptions

Vector clocks require clock synchronization; they can totally order all events; they are necessary for all distributed algorithms.

Explainer

From your study of logical clocks (Lamport clocks), you know that distributed systems can assign timestamps to events without relying on synchronized physical clocks. Lamport clocks give you a useful property: if event A happened before event B, then A's timestamp is less than B's. But the converse is not true — if A's timestamp is less than B's, you cannot conclude that A actually caused B. They might be completely independent events that happened to get ordered by the counter. Vector clocks solve this limitation by making causality detection precise in both directions.

A vector clock is an array of integers, one entry per process in the system. If there are three processes (P1, P2, P3), every event carries a vector like [2, 0, 1]. Each process maintains its own vector and follows two rules. First, before recording a local event, a process increments its own entry in the vector. Second, when a process receives a message, it takes the element-wise maximum of its own vector and the vector attached to the message, then increments its own entry. These two rules are all it takes to capture the full causal history of every event.

The comparison rule is what makes vector clocks powerful. Event A happened before event B if and only if every entry in A's vector is less than or equal to the corresponding entry in B's vector, and at least one entry is strictly less. If neither A ≤ B nor B ≤ A — that is, A has some entries larger than B's and B has some entries larger than A's — then A and B are concurrent. They occurred independently, with no causal chain connecting them. This is information that Lamport clocks simply cannot provide. For example, if A = [2, 3, 1] and B = [3, 1, 2], then A and B are concurrent: A knows more about P2's history, B knows more about P1 and P3. Neither could have influenced the other.

This concurrency detection is essential for conflict resolution in distributed databases. Systems like Amazon's Dynamo use vector clocks (or their compressed variants, version vectors) to detect when two replicas have diverged. If two updates to the same key have comparable vector clocks, the system can automatically keep the later one. If the vectors are incomparable, the system knows a genuine conflict has occurred and can flag it for resolution — either by the application or through a merge function like last-writer-wins. Without vector clocks, the system would have no principled way to distinguish "one update supersedes the other" from "two updates happened independently and both matter."

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra → Boolean Algebra and Fundamental Laws → Logic Gates Fundamentals → Implementing Boolean Functions with Gates → Karnaugh Map Simplification → Combinational Circuit Design → Flip-Flops and Latches → Binary Counters: Design and Analysis → Binary Arithmetic → Fixed-Point Number Representation → Two's Complement Representation → Overflow and Underflow Detection → Binary Adders: Half-Adders and Full-Adders → Full Adder and Carry Propagation → Carry Lookahead Adder Design → Half Adder Circuit Design → Multiplication Circuit Design → Sequential Circuit Design → Registers and Register Files → Instruction Set Architecture (ISA) → Kernel Architecture and OS Structure → System Calls and User/Kernel Mode → Processes and the Process Control Block → Logical Clocks and Event Ordering → Vector Clocks and Capturing Causality

Longest path: 96 steps · 358 total prerequisite topics

Prerequisites (1)

Leads To (2)