---
title: "Need of logical clock synchronization"
subject: "Distributed System"
chapter: 5
key: "semester_7/distributed_system:logical-clock-sync-need"
source: https://www.bctengineer.com/q/semester_7/distributed_system/logical-clock-sync-need
site: BCT Engineering
---

# Need of logical clock synchronization

Distributed System · Chapter 5: Time and State in Distributed Systems

- Asked in: Model question
- Video: [Logical Clocks 🔥🔥](https://www.youtube.com/watch?v=nps88TsKFE4) — Perfect Computer Engineer
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_7/distributed_system/logical-clock-sync-need
- Whole chapter: https://www.bctengineer.com/md/semester_7/distributed_system/chapter-5

## Question

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.

## 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.

## Answer

#### 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
1. Each process Pi has a counter Ci = 0.
2. Before every event, Ci = Ci + 1.
3. A message carries t = Ci of the send event.
4. On receipt of (m, t): Ci = max(Ci, t) + 1.
5. 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.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Why are logical clocks needed?
   A. They give UTC time
   B. They remove message delay
   C. Physical clocks cannot be exactly synchronised and many applications need only event order
   D. They avoid all coding
   Answer: C. Order is what mutual exclusion and replication need. (Key point: Why logical)

2. Why do the two bank replicas become inconsistent in the example?
   A. Messages are lost
   B. Interest is not applied
   C. Clocks drift
   D. Deposit and interest are applied in different order at the replicas
   Answer: D. (1000+100)*1.01 = 1111 vs 1000*1.01+100 = 1110. (Key point: Replica example)

3. Both updates get timestamp 5 (K and P). How do replicas agree on order?
   A. Break ties by process id
   B. Use real time
   C. Discard one
   D. Choose randomly
   Answer: A. The (C, id) order is identical everywhere. (Key point: Tie-break)

4. What is a limitation of Lamport logical clocks?
   A. They need a time server
   B. C(a) < C(b) does not prove a -> b
   C. They cannot order events
   D. They run backwards
   Answer: B. Vector clocks resolve this. (Key point: Limitation)

## Related in Distributed System

- [Clock synchronization need; Lamport](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Aclock-sync-lamport-need) — Distributed System, chapter 5
- [Vector clock synchronization algorithm](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Avector-clock-algorithm) — Distributed System, chapter 5, asked 2×
- [Lamport's logical clock algorithm](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Alamport-clock) — Distributed System, chapter 5, asked 5×
- [Physical clock synchronization algorithm](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Aphysical-clock-sync-algorithm) — Distributed System, chapter 5
- [Physical vs logical clock; sync method](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Aphysical-clock-sync-difficulty) — Distributed System, chapter 5, asked 2×
- [Synchronising physical clock using logical clock](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Async-physical-with-logical) — Distributed System, chapter 5, asked 2×

## Related in other subjects

- [Clock synchronization in DFS](https://www.bctengineer.com/question.md?key=semester_8%2Fbig_data_technologies%3Aclock-synchronization-dfs) — Big Data Technologies, chapter 1
- [Distributed parameters and current along a long line](https://www.bctengineer.com/question.md?key=semester_4%2Fpower_system_analysis_i%3Adistributed-parameters-long-line-current) — Power System Analysis I, chapter 5
- [Distributed system in big data example](https://www.bctengineer.com/question.md?key=semester_8%2Fbig_data_technologies%3Adistributed-system-example) — Big Data Technologies, chapter 1
- [Short note: Distributed system implementation](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Ashort-note-distributed-implementation-issues) — Object Oriented Analysis and Design, chapter 4
