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

Vector Clock Operations

Learning how to increment, merge, and compare vector clocks to determine event relationships.

Vector Clock Operations

You'll learn how to manipulate vector clocks through increment, merge, and compare operations to track causality in distributed systems.

Core Idea

Vector clocks track causality across distributed processes, but they're only useful if we can operate on them correctly. Three fundamental operations enable this: incrementing (updating local state), merging (incorporating remote information), and comparing (determining event relationships).

The Three Essential Operations

1. Increment

When a process performs a local event, it increments only its own entry in the vector clock. If Process A has clock [2, 0, 1] and performs an event, it becomes [3, 0, 1].

Analogy: You turn the page in your personal diary while leaving everyone else's page numbers unchanged.

2. Merge (Update on Receive)

When receiving a message, a process takes the element-wise maximum of its clock and the incoming clock, then increments its own entry. If Process B with [1, 3, 2] receives a message with clock [3, 0, 1], it first merges to [3, 3, 2], then increments to [3, 4, 2].

Why? This captures both local progress and all causality the sender knew about.

3. Compare

To determine if event A happened before event B, check if A's clock is less than or equal to B's clock in every position, and strictly less in at least one. Clocks [2, 1, 0] and [2, 3, 1] show A happened before B. If neither clock dominates, events are concurrent.

Key Takeaway: Vector clock operations—increment for local events, merge-then-increment for receiving messages, and element-wise comparison—enable distributed systems to precisely track which events caused which others, even without synchronized physical clocks.