What is a Lamport Clock?

When data is stored across multiple servers in a distributed system, it is crucial to determine the order in which operations occurred to maintain consistency and ensure the system behaves correctly. But why can’t we rely on the system timestamps? Non-monotonicity of System Clocks: System clocks are not guaranteed to be strictly increasing over time (monotonic). For instance, when servers synchronize their time using the Network Time Protocol (NTP), the clock may be adjusted backward if it was ahead of the actual time. This backward adjustment can create confusion in determining the true order of events, as a later operation might appear to have occurred before an earlier one. Crystal Oscillator Drift: System timestamps are generated based on the server’s internal clock, which relies on a crystal oscillator. Over time, this oscillator can drift, causing the server’s clock to become slightly inaccurate. To correct this drift, NTP is used, but this correction process can cause time to “jump” backward or forward, further complicating event ordering. Incomparable Clocks Across Servers: Even if each server had a perfectly accurate clock, the timestamps from different servers cannot be directly compared. Each server’s clock might be slightly ahead or behind others, leading to inconsistent time comparisons across the system. Lamport Clocks to the Rescue To address these challenges, Lamport Clocks are used. Lamport Clocks provide a way to assign a logical timestamp to events in a distributed system, ensuring a consistent order of events. ...

August 25, 2024 · 4 min