← Lab

Logical Clocks

Send messages between nodes. Compare how Lamport clocks and vector clocks track causality.

Click a node to select sender, then click another to send a message. Click the same node for an internal event.
A B C
Click a node to begin.

How Logical Clocks Work

Lamport Clocks

A Lamport clock is a single integer counter per node. Three rules: increment before any event, attach the counter to every message you send, and on receive take the max of your counter and the message's counter then increment. This gives you a total order — every event gets a unique timestamp.

The catch: if L(A) < L(B), that tells you A might have caused B. But it might not — A and B could be completely independent events that just happened to get ordered timestamps. Lamport clocks can't tell the difference.

Vector Clocks

A vector clock gives each node a vector with one entry per node in the system. On any event — internal, send, or receive — a node increments its own entry. When receiving a message, the node merges by taking the component-wise maximum of its own clock and the message's clock, then increments its own entry.

This produces a partial order. If every component of clock V1 is less-than-or-equal-to every component of V2 (with at least one strict inequality), then V1 happened before V2. If neither clock dominates the other, the events are concurrent — they happened independently, with no causal relationship.

The Difference

Click an event dot in the timeline to see its causal past highlighted in blue and concurrent events highlighted in amber. Enable "Show Lamport Clocks" above to see both timestamps side by side — the amber concurrent events are the ones where Lamport timestamps would impose a false ordering that doesn't actually exist.

Related: Logical Clocks in Distributed Systems