Three Clocks are Better than One
TigerBeetle 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.
Related posts
- Tracking Time Without Clock
TigerBeetle mediumAdeptInstead 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.
- Living without atomic clocks: Where CockroachDB and Spanner diverge
Cockroach Labs hardMasterCockroachDB borrows Spanner's TrueTime-inspired approach to ordering distributed transactions but replaces atomic-clock-bounded certainty with a looser uncertainty interval and uncertainty restarts. Spanner waits out a tight TrueTime bound (about 7 ms) after writes to guarantee linearizability, while CockroachDB assigns provisional timestamps from local wall clocks and retries reads that hit keys within the clock-offset uncertainty interval, providing serializability rather than linearizability. The tradeoff is occasional read restarts—bounded by the configured maximum clock offset, up to roughly 250 ms with NTP—instead of delaying every write; CockroachDB also uses causality tokens to preserve ordering across causally related transactions. Nodes that exceed the maximum configured clock offset self-terminate.
- PTP: Timing accuracy and precision for the future of computing
Meta Engineering easyNoviceMeta is rolling out Precision Time Protocol (PTP) across its data centers to replace NTP, moving clock synchronization precision from milliseconds to nanoseconds. Accurate offset measurement depends on network latency being consistent and symmetric, so PTP uses hardware timestamping to improve consistency and transparent clocks to improve symmetry. Meta removed boundary clocks so every machine syncs directly with the Server Clock. Because off-the-shelf gear could not handle PTP at its scale, Meta built its own Time Appliance (a GNSS receiver plus a miniaturized atomic clock) and a PCIe Time Card, and has open-sourced the hardware, client software and transparent clock through the Open Compute Project.
- 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.
- How Precision Time Protocol is being deployed at Meta
Meta Engineering hardMasterMeta replaced NTP with Precision Time Protocol across its data centers to get nanosecond-level clock sync. Its main motivating use is commit-wait reads that bound clock uncertainty and avoid quorum reads, which ran roughly 100x better on PTP than on NTP in Meta's experiments. The design has three parts. The PTP rack has GNSS-over-fiber antennas and OCP Time Cards disciplined by oscillatord, with NIC clocks aligned via ts2phc and PPS to within ±50ns. The network uses unicast PTP with transparent clocks instead of boundary clocks. Clients are served by ptp4u, an open-source Go PTP server handling over 1 million clients per appliance, with c4u generating dynamic clock class and accuracy and Calnex Sentinel independently monitoring the setup.