NTP Time Sync
NTP (Network Time Protocol, RFC 5905) is the protocol used to synchronize the clocks of computers over a network, achieving accuracy within a few milliseconds of UTC on local networks and tens of milliseconds over the public internet.
NTP (Network Time Protocol, RFC 5905) is the protocol used to synchronize the clocks of computers over a network, achieving accuracy within a few milliseconds of UTC on local networks and tens of milliseconds over the public internet.
Accurate time is foundational to distributed systems: TLS certificate validity, JWT expiration, log correlation, distributed tracing, database ordering, and cryptographic protocols all depend on synchronized clocks. Clock drift of even a few seconds can cause authentication failures, event ordering bugs, and security vulnerabilities.
Stratum Hierarchy: NTP uses a hierarchical, layered architecture called strata. Stratum 0 devices are reference clocks — GPS receivers, atomic clocks, or radio signals like WWVB. Stratum 1 servers (e.g., time.cloudflare.com, pool.ntp.org) are directly connected to stratum 0 devices. Stratum 2 servers synchronize from stratum 1, and so on. Clients typically use stratum 2 or 3 servers.
Client-Server Exchange: NTP uses UDP port 123. The client sends a request with its current timestamp (T1). The server records the arrival time (T2), processes the request, and records the send time (T3). The client records the arrival time (T4). From these four timestamps, both the round-trip delay ((T4-T1) - (T3-T2)) and clock offset (((T2-T1) + (T3-T4)) / 2) can be computed.
Offset Correction: The client uses the computed offset to adjust its local clock. NTP applies adjustments gradually (slewing) rather than jumping the clock, to avoid disrupting time-sensitive applications. Adjustments larger than 128ms trigger a step change.
Modern alternatives like Roughtime and Chrony improve on NTP's security and accuracy. Google and Amazon operate their own NTP infrastructure with leap-second smearing for cloud workloads.