- Model question
Need of logical clock synchronization
Short answer
Logical clock synchronization assigns timestamps respecting causal order without real time. It is needed for ordering updates in replicated databases, mutual exclusion, and snapshots. For example, two bank updates must be applied in the same order at all replicas to avoid inconsistency. Lamport's algorithm: increment counter per event, timestamp messages, and on receive set counter to max(local, received)+1.
What is logical clock synchronization? What is the need of logical clock synchronization in distributed system? Justify the need with suitable example along with a logical clock synchronization algorithm.
Logical clock synchronization
Logical clock synchronization means giving every event in a distributed system a logical timestamp (counter value) so that the timestamps agree with the causal "happened-before" order (a → b implies C(a) < C(b)). It is not tied to real time and needs no time server.
Need
- Distributed systems have no global clock, and physical clocks cannot be synchronised exactly because of drift and variable message delays.
- Many applications need only the same order of events at all nodes: mutual exclusion, totally ordered multicast, replicated database updates, consistent snapshots and deadlock detection.
Example
A bank account with balance Rs 1000 is replicated at Kathmandu and Pokhara. Two clients issue two updates almost simultaneously, and each update is sent to both replicas: update 1 deposits Rs 100 and update 2 adds 1% interest. If the replicas apply them in different orders, one gets (1000 + 100) × 1.01 = 1111 and the other gets 1000 × 1.01 + 100 = 1110, so the replicas become inconsistent. Logical timestamps order the two updates, so all replicas apply them in the same order.
Lamport's algorithm
- Each process Pi has a counter Ci = 0.
- Before every event, Ci = Ci + 1.
- A message carries t = Ci of the send event.
- On receipt of (m, t): Ci = max(Ci, t) + 1.
- For a total order use (Ci, process id); ties are broken by id.
In the example, both updates get timestamps, e.g. (5,K) and (5,P); with the tie broken by id, both replicas order K's update first, and the results agree.
Limitation: C(a) < C(b) does not prove a → b; vector clocks solve this.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Clock synchronization need; Lamport · Distributed System, chapter 5
- Vector clock synchronization algorithm · Distributed System, chapter 5 · asked 2×
- Lamport's logical clock algorithm · Distributed System, chapter 5 · asked 5×
- Physical clock synchronization algorithm · Distributed System, chapter 5
- Physical vs logical clock; sync method · Distributed System, chapter 5 · asked 2×
- Synchronising physical clock using logical clock · Distributed System, chapter 5 · asked 2×
- Clock synchronization in DFS · Big Data Technologies, chapter 1
- Distributed parameters and current along a long line · Power System Analysis I, chapter 5
- Distributed system in big data example · Big Data Technologies, chapter 1
- Short note: Distributed system implementation · Object Oriented Analysis and Design, chapter 4