Lädt...


🔧 Logical Clocks and Clock Synchronization in Distributed Systems


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

As software engineers, when building products using state-of-the-art cloud technologies such as message brokers, queues, etc., we often overlook a very simple aspect of these large-scale systems spread across multiple machines. A concept that prevents unpredicted outcomes from happening — Clock Synchronization (aka. Time).

In simple terms, clock synchronization ensures that the clocks of all the entities constituting a distributed system align closely, allowing to correctly predict the order of the occurrence of the events for the coordination across different processes in the system. But practically, that’s not the case.

Why Clock Synchronization is Hard?

Clocks on different nodes can be built differently. Some may be using quartz crystal while others may be utilizing atomic vibrations (atomic clocks) to measure time. Over time these clocks can start drifting apart due to variations in their counting rates resulting in clock drift. For example, quartz clocks are susceptible to environmental factors such as temperature changes, which impact their correctness.

While one may argue that atomic clocks are more accurate and less susceptible to environmental effects than quartz clocks, there is still a high chance that the clock drift will be present in a system of multiple nodes each with a different clock type.

This scenario of not having a 100% correct sense of physical time on each node of the system, makes clock synchronization hard.

Fig. Clock Synchronization Problem
Fig. Clock Synchronization Problem

Partial Ordering with Logical Clocks

Although using physical clocks to timestamp the data packets in a distributed system may be prone to clock synchronization issues, the initial notion of physical time — an event A happened before an event B if A occurred at an earlier time than B, can still be preserved using logical clocks.

In simple words, if there never existed physical time, then we would still be able to assign chronological order to certain events. For eg. if person A is older than person B, it can be concluded that person A was born before person B. Similarly in a distributed system if a read returns data from a DB, then the create/insert data event must have happened before the read event (assuming the DB was empty initially). Despite not having physical timestamps, these operations can still be chronologically ordered.

Just like the examples above, if we can align on a way to define that an event A “happened before” an event B, without using a physical clock then we can find the correct ordering of the events by the notion of causality.

Mathematically speaking,

  • if A and B are events in the same process and A occurs before B, then A —> B, where “—>” denotes “happens before”,

  • if A is the sending of a message by one process and B is the receipt of the same message by another process, then A —> B,

  • if A —> B and B —> C, then A —> C

A simple logical clock (a counter) which is incremented before any operation/event. In this figure, A1 → A2 →B3 →B4 → C5
A simple logical clock (a counter) which is incremented before any operation/event. In this figure, A1 → A2 →B3 →B4 → C5

However, there will always be some events that are not related and hence can’t satisfy the notion of causality. These so-called concurrent _events will impede achieving _total ordering in a system. Therefore, only partial ordering of the events can be achieved using logical clocks.

Events A1 and C1 are not related, hence concurrent events. They can’t be chronologically ordered.
Events A1 and C1 are not related, hence concurrent events. They can’t be chronologically ordered.

References

This article was originally published in The Scalable Thread newsletter. If you enjoyed reading it, please consider subscribing FREE to the newsletter to support my work and to receive the next post directly in your inbox.

...

🔧 Logical Clocks and Clock Synchronization in Distributed Systems


📈 85.24 Punkte
🔧 Programmierung

🔧 Part II: Foundations of Logical Thinking in Programming, Logical Connectors


📈 33.67 Punkte
🔧 Programmierung

🐧 Instantaneous RTP synchronization & retrieval of absolute sender clock times with GStreamer


📈 30.03 Punkte
🐧 Linux Tipps

🔧 Achieving Precise Clock Synchronization on AWS


📈 30.03 Punkte
🔧 Programmierung

🔧 The Art of Data Synchronization in HarmonyOS Next: Creation and Management of Distributed Data Objects


📈 29.21 Punkte
🔧 Programmierung

🔧 The Art of Data Synchronization in HarmonyOS Next: The Use of Distributed Databases and Data Protection


📈 29.21 Punkte
🔧 Programmierung

🔧 The Art of Data Synchronization in HarmonyOS Next: Creation and Management of Distributed Data Objects2


📈 29.21 Punkte
🔧 Programmierung

🔧 The Art of Data Synchronization in HarmonyOS Next: Distributed Objects and Cross-Device Invocation


📈 29.21 Punkte
🔧 Programmierung

🐧 Clock: a fullscreen clock with seconds, date, and day of the week for Windows and Linux


📈 28.43 Punkte
🐧 Linux Tipps

🐧 [release] brig 0.4.0: distributed, versioned & secure file synchronization


📈 27.95 Punkte
🐧 Linux Tipps

🔧 Distributed Task Synchronization: Leveraging ShedLock in Spring


📈 27.95 Punkte
🔧 Programmierung

🍏 World Clock Deluxe 4.19.1 - World time clock and meeting planner.


📈 27.17 Punkte
🍏 iOS / Mac OS

📰 Clock blocker: Woman sues bosses over fingerprint clock-in tech


📈 25.91 Punkte
📰 IT Security Nachrichten

🍏 The Clock 4.9 - World clock, meeting planner, calendar.


📈 25.91 Punkte
🍏 iOS / Mac OS

🍏 Second Clock 1.0.0 - Second clock for a different time zone in your menu bar.


📈 25.91 Punkte
🍏 iOS / Mac OS

🐧 GitHub - coffee-o-clock: A clock that let's you understand if you should have another cup of coffee.


📈 25.91 Punkte
🐧 Linux Tipps

🕵️ CVE-2024-9593 | Time Clock Plugin/Time Clock Pro Plugin on WordPress improper authentication


📈 25.91 Punkte
🕵️ Sicherheitslücken

🔧 Physical and Logical Memory: Addressing and Allocation in Operating Systems


📈 25.31 Punkte
🔧 Programmierung

🔧 Process Synchronization in Operating Systems: Key Challenges and Solutions


📈 24.29 Punkte
🔧 Programmierung

🐧 Comparing thermals, clocks and performance of R5 3500X and i5-9400F under Linux


📈 22.79 Punkte
🐧 Linux Tipps

🎥 How Do PCs and Phones Set Their Own Clocks?


📈 21.53 Punkte
🎥 Videos

🔧 Go time and its two clocks


📈 21.53 Punkte
🔧 Programmierung

📰 From Atomic to Nuclear Clocks - and a Leap in Timekeeping Accuracy?


📈 21.53 Punkte
📰 IT Security Nachrichten

📰 While You Were Offline: Hey Y’All, Remember to Set Your Doomsday Clocks Forward


📈 20.27 Punkte
📰 IT Nachrichten

📰 Physicists Find That As Clocks Get More Precise, Time Gets More Fuzzy


📈 20.27 Punkte
📰 IT Security Nachrichten

📰 Lithuania Calls On EU To Stop Adjusting Clocks For Daylight Savings


📈 20.27 Punkte
📰 IT Security Nachrichten

matomo