Determining expiry - distributed nodes - without syncing the clocks
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
In distributed systems, managing the expiration of data or events without synchronized clocks among nodes presents complex challenges. Nodes in such systems may sometimes skew in time, leading to inconsistencies in data expiration. This article explores methods and strategies to handle expiry in distributed nodes without the need for synchronized clocks.
Logical Clocks and Version Vectors
One common approach is the use of logical clocks to track the sequence of events rather than real-time. A logical clock, like the Lamport timestamp, increases with each event, ensuring a partial ordering of events across the distributed system. This means that although we may not know the exact real-world time when data should expire, we can determine an expiration based on event counts or sequences.
For example, if a data element is set to expire after 100 events, it will be deemed expired once the logical clock counts 100 subsequent events, regardless of the actual wall-clock time elapsed.
Vector Clocks
Vector clocks extend the concept of logical clocks by maintaining a vector of logical timestamps, one for each node in the distributed system. This vector enables a system to not only know the sequence of events but also the relative causality between events. This causal information can be crucial in determining data validity or expiration.
When a node receives a vector clock timestamp from another node, it can determine if the received event has happened before or after its own events. This can effectively coordinate action-like data expiration based on the event history rather than time.
Time-based UUIDs
Another technique utilizes UUIDs generated with embedded timestamps (e.g., Version 1 UUIDs). While these do use real-time clocks, they do not require nodes' clocks to be perfectly synchronized. They incorporate the node's MAC address and the timestamp at the time of UUID generation. This allows the system to check the UUID to infer an approximate time of creation and thus manage expiration by assessing UUIDs rather than relying strictly on synchronized node clocks.
Hashed Time-Locked Contracts (HTLCs)
In blockchain technologies and similar systems, HTLCs provide a method to enforce agreements (such as expirations) securely between parties without needing synchronized clocks. These contracts lock transactions with a cryptographic hash puzzle and set a relative timeout based on the number of blocks added to the blockchain, rather than specific timestamps. This way, data expiration or transaction completion can be managed deterministically in a decentralized environment.
Challenges and Considerations
- Clock Skew: Even with logical and vector clocks, the real-world execution still somewhat depends on the physical clocks, which can be skewed. Developers need to design systems that can tolerate some degree of clock drift.
- Network Delays: Messages bearing timestamps or event sequences can be delayed, complicating the expiration calculations.
- Trust and Security: Using timestamps from possibly untrustworthy nodes requires mechanisms to validate and secure time-related data.
Summary Table
| Technique | Mechanism | Considerations |
| Logical Clocks | Event counting; no real-time | Sensitive to high event throughput |
| Vector Clocks | Event causality and sequencing | Complex to implement; higher overhead |
| UUID-based Timestamps | Embedded approximate time | Requires loose clock synchronization |
| HTLCs | Block-based event counting | Dependent on blockchain’s integrity and delay |
Conclusion
Dealing with data expiry in distributed systems without syncing clocks involves various innovative techniques, each with its pros and cons. Depending on system requirements—accuracy, complexity, overhead, and fault tolerance—different strategies might be suitable. Understanding the underlying mechanisms of these approaches allows system designers to handle discrepancies in clocks and ensure consistent data and operation expiry across distributed nodes.
By effectively using these strategies, distributed systems can operate more robustly and rely less on strict clock synchronization, thus enhancing their scalability and practicality in real-world decentralized applications.

