Tracking Time Without Clock
Instead of threading a full virtualized Clock interface through every component, two lighter patterns often suffice for handling time in reliable systems. Passing a `now: Instant` argument to methods (call-site dependency injection) lets components like TigerBeetle's adaptive replication routing measure durations without owning a clock, and makes edge cases like time overflow trivial to test. For scheduling future work, a `tick` method invoked at a fixed cadence by the caller gives coarse but sufficient time resolution and greatly simplifies control flow and testing.
Related posts
- Building On-call: Time, timezones, and scheduling
incident.io mediumAdeptincident.io's on-call scheduler computes who is on shift from rotations with working hours, round-robin handovers and overrides, and getting it right depends on being precise about local time, offsets, IANA timezones, instants and durations. The design keeps everything as UTC instants (Postgres timestamptz, Go's time package) and converts to wall-clock time only at the edges or in isolated, well-tested calculations such as working hours. Users wanted schedules shown in their own timezone, and sometimes several at once, rather than the schedule's timezone. Correctness rests on unit-tested building blocks, JSON snapshot tests of schedule evaluations flagged in PRs via danger.js, and a periodic runtime audit job that re-evaluates active schedules against the cached on-call state.
- Three Clocks are Better than One
TigerBeetle mediumAdeptTigerBeetle builds a fault-tolerant "cluster time" by measuring clock offsets to peers during keepalive probes. Each offset combines the peer's wall-clock timestamp with half the round-trip time, and the best low-latency samples from windows of up to 20 seconds are fed to Marzullo's algorithm, which yields bounds agreed by a majority of clocks. That lets a server correct its system time when NTP silently fails, or shut down safely if too many clocks are faulty. Elapsed time should be measured with CLOCK_BOOTTIME rather than CLOCK_MONOTONIC, which stops counting during system suspend (e.g. VM migration), or CLOCK_MONOTONIC_RAW, which exists for NTP to measure oscillator drift.
- Run Scheduled and Recurring Tasks with Cron
Railway mediumAdeptCron runs commands on time-based schedules but keeps no job history, has no retries and does no concurrency control, so reliability depends on the job itself. The guide covers the five-field schedule syntax, including the day-of-month/weekday OR pitfall and timezone/DST issues, and recommends idempotent upserts, structured start/success/error logs, explicit connection cleanup, and Postgres advisory locks to prevent overlapping runs. On Railway, cron triggers a service's start command in UTC with a 5-minute minimum interval and a single active execution. A process left alive by open handles or pending promises causes later runs to be skipped.
- Building On-call: Continually testing with smoke tests
incident.io mediumAdeptincident.io runs an end-to-end smoke test suite for its On-call paging product every minute against production and staging, and also on every pull request and deploy using containers on a single machine. The suite covers core journeys such as alert ingestion and escalation paging, plus edge cases like malformed user JavaScript in alert parsing. Lessons drawn from building it: have each test begin by tearing down leftover state from earlier runs, set up data through the application's own abstractions rather than direct database or ORM writes, and assert on user-visible timing rather than database rows alone. Running continuous traffic also exposed hidden scaling assumptions, such as migrations that slowed down and batch operations that needed rethinking.
- A Tale Of Four Fuzzers
TigerBeetle hardMasterTigerBeetle's Adaptive Replication Routing (ARR) puts the primary in the middle of a replication ring so no single dropped message is critical. It also reorders replicas dynamically by running routing experiments and measuring end-to-end prepare_ok latency rather than modeling the network. Testing it took four different fuzzers rather than relying only on the VOPR whole-system simulator. The key lesson is to design subsystems around minimal, data-oriented interfaces (integers for op, time and view instead of injected clocks or replicas) so they can be fuzzed in isolation. Small state spaces such as route encoding can be exhaustively enumerated instead of randomly sampled.