Clock Synchronization in Distributed System With Algorithm and Example
Clock Synchronization in Distributed System With Algorithm and Example. In this lecture You will learn about the Clock and its working with different time zone in the Globe.
Clock Synchronization in Distributed System With Algorithm And Example Clock Synchronization Algorithm Clock Synchronization Example Synchronization In Distributed Systems Clock Synchronization In Distributed System Berkeley Algorithm Clock Synchronization.

Clock Synchronization Algorithms What Is Clock Synchronization In Distributed System Types Of Clock Synchronization In Distributed System Synchronization In Distributed Systems Video Lecture Clock Synchronization In Distributed System Video Logical Clock Synchronization In Distributed System.
Contents
- 1 Clock Synchronization in Distributed Systems
- 2 Why is Clock Synchronization Needed?
- 3 Types of Clock Synchronization
- 4 External Synchronization
- 5 Internal Synchronization
- 6 Clock Synchronization Algorithms
- 7 Cristian’s Algorithm (Client-Server Model)
- 8 Berkeley’s Algorithm (Master-Slave Model)
- 9 Lamport Timestamps (Logical Clock, No Physical Time)
- 10 Which Algorithm to Use?
- 11 Final Thoughts
- 12 Clock Synchronization in Distributed System With Algorithm and Example
- 13 distributed os- unit 3 clock synchronization – econtent.in
- 14 Clock Synchronization in Distributed Systems
Clock Synchronization in Distributed Systems
In distributed systems, different machines (nodes) have their own clocks, which can drift due to hardware differences, network delays, or processing times. Clock synchronization ensures that all nodes in the system agree on a common time.
Why is Clock Synchronization Needed?
Ordering Events Correctly – Ensures event timestamps are consistent.
Preventing Inconsistencies – Avoids conflicts in databases and transactions.
Security & Logging – Helps in fraud detection, debugging, and audit logs.
Example:
Imagine a bank’s distributed system:
- Node A records a withdrawal at 12:30 PM
- Node B records a deposit at 12:29 PM
- If clocks are not synchronized, the system may process transactions incorrectly.
Types of Clock Synchronization
External Synchronization
- Clocks are synchronized with an external time source like NTP (Network Time Protocol).
- Used in real-world systems like Google Spanner and financial trading systems.
Internal Synchronization
- Clocks in all nodes of a distributed system are synchronized with each other but not necessarily with an external source.
Clock Synchronization Algorithms
Cristian’s Algorithm (Client-Server Model)
Used when one machine has access to an accurate time source.
Works by requesting time from a time server and adjusting local clocks.
Algorithm Steps
- A client sends a time request to the time server.
- The server replies with its current time.
- The client calculates the round-trip delay and adjusts its clock.
Example:
- Client sends request at T1 = 10:00:00
- Server receives request and replies at T2 = 10:00:05
- Client receives response at T3 = 10:00:08
- Estimated time = T2+(T3−T1)2T2 + \frac{(T3 – T1)}{2} = 10:00:05+(8−0)210:00:05 + \frac{(8-0)}{2} = 10:00:09
Limitation: Network delays can introduce errors.
Berkeley’s Algorithm (Master-Slave Model)
Used in systems where no external time source is available.
A master node calculates an average clock time for all nodes.
Algorithm Steps
- The master node polls all nodes for their current time.
- It calculates the average time, ignoring outliers.
- The master instructs nodes to adjust their clocks accordingly.
Example:
Node | Reported Time | Difference | Adjustment |
---|---|---|---|
A | 10:00:05 | -3 sec | Add 3 sec |
B | 10:00:10 | +2 sec | Subtract 2 sec |
C (Master) | 10:00:08 | 0 sec | No change |
Limitation: Assumes master clock is accurate.
Lamport Timestamps (Logical Clock, No Physical Time)
Used in event ordering when precise time synchronization is difficult.
Algorithm Steps
- Each process maintains a logical clock.
- Every event increments the logical clock.
- If Process A sends a message to Process B, B sets its logical clock to max(A’s clock, B’s clock) + 1.
Example:
Event | Process A | Process B | Process C |
---|---|---|---|
Start | 1 | 1 | 1 |
A sends msg to B | 2 | – | – |
B receives msg | – | 3 | – |
Limitation: Only provides event ordering, not absolute time synchronization.
Which Algorithm to Use?
If an external time source is available → Use NTP or Cristian’s Algorithm
If no external time source → Use Berkeley’s Algorithm
If ordering events is important → Use Lamport Timestamps
Final Thoughts
Clock synchronization is crucial in distributed systems for data consistency, event ordering, and security. The choice of algorithm depends on network conditions, system architecture, and accuracy requirements.
Want a real-world implementation of these algorithms in Python? Let me know!