Skip to main content

Physical vs logical clocks; Lamport

Short answer

Physical clocks measure real time and need synchronization; logical clocks are counters that only order events. Lamport's algorithm increments a counter before each event, attaches it to messages, and on receive takes max with the received timestamp plus one. Benefits: simple and small; drawback: C(a) < C(b) does not imply causality.

Compare physical clocks and logical clocks with its implementation semantics. Describe Lamport's timestamp algorithm with its benefits and drawbacks.

Physical vs logical clocks

PointPhysical clockLogical clock
MeasuresReal time (UTC)Order of events only
ImplementationHardware oscillator, synchronised by Cristian, Berkeley, NTPSoftware counter (integer or vector)
Value meaningTime of dayCount, no relation to real time
DriftDrifts, needs periodic correctionNo drift issue
Needs time serverUsually yesNo
SemanticsEvent a before b if time(a) < time(b)a → b implies C(a) < C(b)
AccuracyLimited by network delayConsistent with causality (exact, if and only if, only for vector clocks)
UseTimestamps, billing, real-time tasksOrdering, mutual exclusion, consistency

Lamport's timestamp algorithm

Each process Pi has a counter Ci (initially 0).

  1. Before every event, Ci = Ci + 1.
  2. A message is sent with timestamp t = Ci.
  3. On receipt of (m, t): Ci = max(Ci, t) + 1.

To get a total order, ties are broken by process id: (Ci, i).

Example: P1 sends m at C=3 (timestamp 3). P2 has C=1; on receipt P2 sets C = max(1,3)+1 = 4, so the receive is later than the send.

Benefits: simple; no physical clock needed; small overhead (one integer); gives an order consistent with causality; useful for distributed mutual exclusion and totally ordered multicast.

Drawbacks: C(a) < C(b) does not imply a → b; concurrent events cannot be identified (vector clocks fix this); no link with real time; a total order can be artificial.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Distributed System chapter 5 questions →