Network Time Protocol (NTP)
You'll learn: How NTP synchronizes physical clocks across distributed machines using a hierarchical network of time servers and round-trip delay compensation.
Why Physical Clock Synchronization Matters
Unlike logical clocks (Lamport timestamps or vector clocks) that only track causal ordering, many real-world systems need accurate physical time. Logging events, security certificates, coordinated actions, and compliance all depend on knowing the actual wall-clock time. But as you've learned, distributed systems have no global clock, and individual machine clocks drift at different rates.
How NTP Works
NTP organizes time servers into strata (levels):
- Stratum 0: Atomic clocks or GPS receivers (reference clocks)
- Stratum 1: Servers directly connected to Stratum 0
- Stratum 2: Servers syncing from Stratum 1
- ...and so on (up to Stratum 15)
Your machine typically queries multiple Stratum 2 or 3 servers to get reliable time.
Compensating for Network Delay
When your machine requests time from an NTP server, the reply takes time to travel. NTP measures round-trip delay:
- Client sends request at local time
T1 - Server receives at
T2, replies atT3(server timestamps) - Client receives at
T4
Round-trip delay: (T4 - T1) - (T3 - T2)
Estimated offset: ((T2 - T1) + (T3 - T4)) / 2
By averaging multiple samples and filtering outliers, NTP achieves millisecond accuracy over the internet and microsecond accuracy on LANs.
Gradual Clock Adjustment
NTP doesn't jump your clock suddenly (which could break applications). Instead, it slews the clock—gradually speeds up or slows down the clock rate until it converges to the correct time.
Key Takeaway: NTP provides practical physical clock synchronization across distributed systems using a hierarchical architecture and round-trip delay measurement, achieving millisecond-level accuracy essential for real-world coordination.