Logical Clocks(I) — Clock Series

In my last article, we learned that despite physical clock synchronization using NTP servers, we might still see a clock skew of around 10ms. What it means is that if you’re trying to build a high throughput distributed system, where the ordering of operations is critical, you might face issues in correctly ordering the operations because of clock skew.

Logical Clocks

As the name suggests, logical clocks represent time through a virtual implementation, that represents a monotonically increasing value.

The easiest example could be taking an integer, which can be incremented every new operation to represent the ordering of operations. As such, we are just counting the number of operations that have occurred & since we use a monotonically increasing value for each operation, we’ll be able to establish causality across operations.

Now, that we know at a high level about logical clocks, let's go into different types of logical clocks -

Lamport Clocks

We talked about happens-before relationships in our previous articles on Strong Consistency Models. We covered total ordering and causal ordering between operations. Causality between operations establishes a dependency between them, where operation 2 may be dependent on the state caused by operation 1. Leslie Lamport suggested a solution to use logical timestamps to track happens-before relationships(Refer to his paper — Time, Clocks and Ordering Of Events). So this…

--

--

Pratik Pandey - https://pratikpandey.substack.com
Pratik Pandey - https://pratikpandey.substack.com

Written by Pratik Pandey - https://pratikpandey.substack.com

Senior Engineer with experience in designing and architecting large scale distributed systems.

No responses yet