Clock skew and drift¶
Category: Distributed systems · Status: stub
One line: Skew is how far apart two machines' clocks are at one moment, drift how fast they move apart — the reason timestamps from different machines cannot reliably order events.
Also called: clock drift, clock synchronization, NTP, PTP, TrueTime.
How it connects¶
flowchart LR
n_clock_skew["Clock skew and drift"]
n_logical_clocks["Logical clocks"]
n_clock_skew ---|or| n_logical_clocks
classDef center stroke-width:3px
class n_clock_skew center
classDef outside stroke-dasharray: 4 3
class n_logical_clocks outside
- An alternative to: Logical clocks
In each language¶
| Rust | Instant ↗ is monotonic; SystemTime ↗ is not, and is the one for communicating with other processes |
| Go | time.Now returns both a wall-clock and a monotonic clock reading ↗, and the monotonic reading has no meaning outside the current process |
| C++ | std::chrono::steady_clock ↗ is monotonic: its time points cannot decrease as physical time moves forward |
| Java | System.nanoTime ↗ measures elapsed time only and is not related to wall-clock time |
| Python | time.monotonic ↗ cannot go backwards and is not affected by system clock updates |
| Erlang and Elixir | the runtime keeps Erlang monotonic time apart from system time, with time warp modes ↗ for when system time changes |
| The operating system | CLOCK_REALTIME ↗ jumps when the system time is changed; CLOCK_MONOTONIC cannot be set |
Where to read more¶
- In the books: Concurrent Programming on Windows, Joe Duffy — ch. 2, 'Synchronization and Time'
- In the books: Distributed Computing, Ajay D. Kshemkalyani, Mukesh Singhal — ch. 3, 'Logical Time' → 'Physical Clock Synchronization: NTP'
- In the books: Modern Multithreading, Richard H. Carver, Kuo-Chung Tai — ch. 6, 'Message Passing in Distributed Programs' → 'Timestamps and Event Ordering'
- In the books: Designing Data-Intensive Applications, Martin Kleppmann — ch. 8, 'The Trouble with Distributed Systems' → 'Unreliable Clocks'
- Notes: clock skew ↗
- Notes: Clock Drift ↗
- Notes: clock synchronization - time synchronization ↗
- Notes: distributed clock ↗
- Notes: distributed time ↗
- Notes: Spanner: TrueTime and external consistency ↗
- Reference: Wikipedia: Clock skew ↗
- Reference: Wikipedia: Clock drift ↗