RTUComputer ScienceYr 2024 · Sem 62024

Q2Distributed System

Question

4 marks

Explain the working of Lamport's Logical Clock with a suitable example.

Answer

A rigorous mathematical exposition of Lamport's Logical Clock, detailing how software counters and the "happens-before" relationship guarantee chronological sanity without requiring physical time synchronization.

Leslie Lamport mathematically proved that synchronizing physical clocks across a massive distributed network is impossible and largely unnecessary. Instead of relying on real-world seconds, he engineered a strict logical architecture based entirely on the Causality of events, known as the "happens-before" relation (denoted as ).

The Mathematical Rules of Execution

Every single Node in the cluster maintains a simple integer software counter , initialized to . The clocks obey two absolute, rigid mathematical rules:

  • Rule 1 (Internal Events): Before Node executes ANY event (computation, reading a file), it violently increments its own clock:
  • Rule 2 (Message Passing): When Node blasts a message to Node , it mathematically piggybacks its current clock value onto the network packet: . When Node receives the message, it MUST aggressively synchronize its own clock to be mathematically higher than both its own current time AND the sender's time. It executes:

Architectural Example

Assume Node A () and Node B (). Node A sends a critical database update to Node B.

  • Node A increments its clock: . It transmits .
  • Node B is already at . When it receives , it executes .
  • Now assume Node B () sends a message to Node A ().
  • Node B increments: . It transmits .
  • Node A receives . Node A mathematically realizes it is wildly behind in the timeline. It aggressively forces its clock forward: .

This mathematical architecture guarantees that if Event X caused Event Y, the timestamp of X will absolutely always be numerically smaller than the timestamp of Y, perfectly preserving causal history across the chaotic network.

Back to Paper