Patterns of Distributed Time

Servers often need to have some sense of temporal ordering to figure out which server holds the latest data and which has stale data. It might appear that we can use system timestamps to order a set of messages, but we cannot. The main reason we cannot use system clocks is that system clocks across servers are not guaranteed to be synchronized.

A time-of-the-day clock in a computer is managed by a quartz crystal and measures time based on the oscillations of the crystal. This mechanism is error-prone: Crystals can oscillate faster or slower, so different servers can have different times. The clocks across a set of servers are synchronized by a service called NTP. This service periodically checks a set of global time servers and adjusts the computer clock accordingly. Because this happens over the network, and network delays can vary, clock synchronization might be delayed because of a network issue. This can cause server clocks to drift away from each other. After the NTP sync happens, they can even move back in time. Because of these issues with computer clocks, time of day is generally not used for ordering events.

Even Google’s TrueTime clock machinery built using GPS clocks has clock skew. However, that clock skew is guaranteed to be bounded by an upper bound. When the clock skew has guaranteed bounds, the system clock can be used by employing a technique called Clock-Bound Wait .

But when the clock skew is not bounded, which is almost always the case, distributed systems often use techniques commonly called a logical timestamp. In the following chapters, we will explore patterns for implementing logical timestamps.