Logical Clocks

Let's explore what logical clocks are and how they help to order events.

The focus of this chapter so far has been on physical clocks and explaining their main limitations when used in distributed systems. Now, let’s explore the use of logical clocks.

What are logical clocks?

Logical clocks are the alternative category of clocks that do not rely on physical processes to keep track of time. Instead, they make use of messages exchanged between the nodes of the system. This is also the main mechanism of information flow in a distributed system, as discussed previously.

Event ordering with logical clocks

We can imagine a trivial form of such a clock in a system that consists of only a single node. Instead of using a physical clock, this node could use a logical clock, which would consist of a single method, say getTime(). When invoked, this method would return a counter, which would subsequently be incremented. For example, if the system started at 9:00 and events A, B and C happened at 9:01, 9:05, and 9:55, respectively, they could be assigned the timestamps 1, 2, and 3. As a result, the system would still be able to order the events, but it would not be able to determine the temporal distance between any two events.

We have described some more elaborate types of logical clocks in the next chapter.

Get hands-on with 1400+ tech skills courses.