liveBook · Manning

Logical clock

As explained in Think Distributed Systems

A logical clock is a distributed-systems mechanism that assigns logical timestamps or ordering information to events without representing physical time.

A logical clock assigns timestamps or ordering information to events without measuring physical time. It orders events through the happened-before relationship, while physical clocks measure duration and can suffer drift, skew, and synchronization problems. section 2.2.4 section 2.2.5

A Lamport clock provides a precise mental model:

  • Each component maintains a counter, increments it at every internal or external step, and tags events with the current value. section 2.2.4
  • When a message arrives, the receiver advances its counter to at least the maximum of its value and the received timestamp plus one. section 2.2.4
  • This gives causally related events strictly increasing logical-time values, but timestamps may not be comparable across independent Kafka partitions. section 2.2.4

Partition offsets as logical time

Kafka assigns each message an offset within its partition. An earlier message has a smaller offset, allowing consumers to track progress; offsets from different partitions cannot be compared. etcd similarly increments a per-key sequence number to support compare-and-swap operations. section 2.2.4

Figure 2.18 Lamport clocks
A diagram of a number and a number

AI-generated content may be incorrect.

Use the Lamport-clock figure to visualize counter advancement across components and message delivery. section 2.2.4

How Think Distributed Systems covers it

How deep it goes
Defines Lamport counters and receive updates, then illustrates applications without implementation-heavy detail.
Examples
Uses Lamport clocks, Kafka partition offsets, and etcd per-key sequence numbers as ordering examples.
What it assumes
Assumes events, components, messages, and happened-before relationships; contrasts logical time with physical time.
What you can do after
Evaluate/understand how logical timestamps order causally related events and why physical time can be insufficient.
How it connects
Connects happened-before, causality, physical clocks, concurrency, Kafka partitions, and etcd sequence numbers.

Also explained in

Compare how 2 books explain logical clock →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Think Distributed Systems. The section links point to the parts of the book it draws on.