Home / Companies / TigerBeetle / Blog / Post Details
Content Deep Dive

Tracking Time Without Clock

Blog post from TigerBeetle

Post Details
Company
Date Published
Author
matklad
Word Count
657
Language
English
Hacker News Points
-
Summary

Handling time in reliable systems can be deceptively complex, even though it appears straightforward. Instead of relying directly on the time functions provided by programming language standard libraries, two code patterns are recommended to manage time effectively. The first pattern, known as "Call Site Dependency Injection," involves passing a single instance of the current time (an "Instant") to methods that need it, simplifying testing by allowing direct construction of time instances. This pattern is demonstrated through its use in adaptive replication routing, where it aids in measuring replication delays without needing a full clock interface. The second pattern focuses on scheduling future work by introducing a regular "tick" method within the system, which is invoked at a fixed cadence, simplifying control flow and reducing precision requirements for future scheduling. These patterns address the essential complexities of time handling, offering practical solutions for different scenarios without resorting to the complete virtualization of the clock.