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.

video

play-rounded-fill play-rounded-outline play-sharp-fill play-sharp-outline
pause-sharp-outline pause-sharp-fill pause-rounded-outline pause-rounded-fill
00:00

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.

 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

  1. A client sends a time request to the time server.
  2. The server replies with its current time.
  3. 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

  1. The master node polls all nodes for their current time.
  2. It calculates the average time, ignoring outliers.
  3. 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

  1. Each process maintains a logical clock.
  2. Every event increments the logical clock.
  3. 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!

Clock Synchronization in Distributed System With Algorithm and Example

distributed os- unit 3 clock synchronization – econtent.in

Clock Synchronization in Distributed Systems

Certainly! Here’s a clear and concise explanation of Clock Synchronization in Distributed Systems, along with algorithms and examples – very useful for understanding distributed computing concepts.


🕒 Clock Synchronization in Distributed Systems

In distributed systems, each machine has its own local clock, which may drift due to hardware differences. To coordinate actions (e.g., logging, transactions, scheduling), clock synchronization is required.


✅ Why Synchronize Clocks?

  • To maintain consistency in timestamps

  • To prevent anomalies in event ordering

  • Required for coordinated actions and logging


📘 Types of Clocks

  • Hardware Clocks: Crystal oscillator-based (drift possible)

  • Logical Clocks: Event-based timestamps (Lamport, Vector)

  • Synchronized Clocks: Use algorithms to adjust time


⚙️ Popular Clock Synchronization Algorithms


1️⃣ Cristian’s Algorithm (External Synchronization)

Goal: Sync client time with a time server.

Steps:

  1. Client sends a time request to the Time Server.

  2. Time Server replies with its current time T.

  3. Client adjusts its clock using:

    Tclient=T+(Tround trip)2T_{\text{client}} = T + \frac{(T_{\text{round trip}})}{2}

Example:

  • Client sends at 10:00:00.000

  • Server replies with 10:00:10.000

  • Round Trip = 100ms

  • Client sets time = 10:00:10.050

Assumes: Symmetrical network delays


2️⃣ Berkeley’s Algorithm (Internal Synchronization)

Goal: Synchronize all nodes to an average time (no external time server).

Steps:

  1. A master node polls all nodes for their current time.

  2. Computes average time (ignores outliers).

  3. Sends adjustments to each node to sync to the average.

Example:

Node Time
A 10:00:00
B 10:00:10
C 09:59:50

Average = 10:00:00

  • A stays same

  • B subtracts 10 sec

  • C adds 10 sec


3️⃣ Lamport Timestamps (Logical Clock)

Goal: Maintain causal order of events, not real-time.

Rules:

  1. Increment clock before each event.

  2. On message send, send current clock.

  3. On message receive, update:

    Creceiver=max⁡(Creceiver,Csender)+1C_{\text{receiver}} = \max(C_{\text{receiver}}, C_{\text{sender}}) + 1

Example:

  • P1 sends message at T=3

  • P2 receives and updates T = max(2, 3) + 1 = 4

Maintains “happens-before” relationship.


🧠 Key Points

Algorithm Sync Type Real Time Use Case
Cristian’s External ✅ Accurate time from server
Berkeley’s Internal Approx Peer-to-peer networks
Lamport Timestamp Logical ❌ Event ordering

📌 Real World Usage

  • NTP (Network Time Protocol) – Uses hierarchical servers to sync clocks globally.

  • Google Spanner – Uses TrueTime API with GPS + atomic clocks for consistency.


✅ Conclusion

Clock synchronization ensures consistency, coordination, and correctness in distributed systems. Depending on the requirements (real-time accuracy or event order), choose the right algorithm.


Would you like a diagram, flowchart, or MCQ worksheet to revise this topic better?

Clock Synchronization in Distributed System With Algorithm and Example

Clock Synchronization – Distributed Systems

Logical Clocks Clock Synchronization



Diznr International

Diznr International is known for International Business and Technology Magazine.

Leave a Reply

Your email address will not be published. Required fields are marked *

error: