liveBook · Manning

Logical clock

As explained in Latency

A logical clock is a protocol-maintained ordering mechanism that represents event or system-state progression without measuring physical time.

A logical clock is a protocol-maintained ordering mechanism for representing event or system-state progression without relying on synchronized physical time. It supports conflict resolution and replica coordination when wall-clock drift makes event ordering unreliable. section 11.3.2 section 4.7

A Lamport timestamp maintains causal order through a local counter:

  • Initialize each process’s counter to zero. section 11.3.2
  • Include the current counter when sending a message. section 11.3.2
  • On receipt, set the local counter to the greater of the local and received values, then increment it. section 11.3.2
  • Compare counter values to order events connected by a causal relationship, commonly called happens-before. section 11.3.2

Logical clocks do not measure elapsed physical time and do not identify which of two concurrent events happened first. Vector clocks can represent concurrency, but require growing metadata for participant state. A node ID can provide a deterministic tie-breaker when conflicting updates share a logical time. section 11.3.2 section 11.3.2

Optimistic updates and replicated views

For last-writer-wins reconciliation, clients can attach a Lamport timestamp or vector clock and node ID to updates instead of trusting synchronized wall clocks. In Viewstamped Replication, each primary-backed period receives a view number; incrementing it during a primary change gives replicas a logical marker for the current system state. section 11.3.2 section 4.7

Figure 11.5 Lamport timestamps record the causal relationship between events. Each process maintains a counter, which increments every time the process sends out a message. The process includes the counter as part of the sent-out message, and when another process receives the message, the process updates its timestamp either to its current value or to the value of the received timestamp, whichever is greater. In this example, you have three processes sending and receiving messages.
Figure 11.5: Lamport timestamps record the causal relationship between events. Each process maintains a counter, which increments every time the process sends out a message. The process includes the counter as part of the sent out message and when another process receives the message, the process updates its timestamp to the maximum of current and the received timestamp. In this example, you have three processes sending and receiving messages.

Trace counter updates across three communicating processes to visualize how Lamport timestamps preserve causal ordering. section 11.3.2

How Latency covers it

How deep it goes
Explains Lamport counter updates and concurrency limits, then contrasts vector clocks without detailing their full algorithm.
Examples
Uses client update reconciliation, concurrent purchases, three communicating processes, and Viewstamped Replication view changes.
What it assumes
Assumes distributed processes, messages, replicas, and synchronized-clock limitations, while defining the logical-counter procedure explicitly.
What you can do after
Apply Lamport timestamps to order causally related messages and choose deterministic outcomes for conflicting distributed updates.
How it connects
Connects logical clocks to causal ordering, last-writer-wins, vector clocks, hybrid logical clocks, and replicated state.

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 Latency. The section links point to the parts of the book it draws on.