← Lessons

quiz vs the machine

Gold1460

Concurrency

Comparing Vector Clocks

Decide happened before, after, or concurrent from per node counters.

6 min read · core · beat Gold to climb

What a vector clock holds

A vector clock is an array with one counter per node. Each process increments its own slot on every event and attaches the whole vector to messages. On receive, a node takes the element wise maximum of its vector and the incoming one, then increments its own slot.

Comparing two vectors

Given vectors V and W:

  • V happened before W if every element of V is less than or equal to the matching element of W and at least one is strictly less.
  • W happened before V by the symmetric rule.
  • If neither dominates, the events are concurrent, which signals a potential conflict.

This is the key advantage over a single scalar Lamport clock: vector clocks can detect concurrency, not just impose a total order.

Cost

The vector grows with the number of nodes, so storage and message overhead are O of n. Systems with many short lived nodes use techniques like dotted version vectors to bound this.

Key idea

Vector clocks compare element wise to classify two events as ordered or concurrent, detecting conflicts that a scalar clock cannot.

Check yourself

Answer to earn rating on the learn ladder.

1. When are two events concurrent under vector clocks?

2. What does a node do with the vector on receiving a message?