Course contentsShow
← System Design
Lesson 1114 of 1,91928. Timeouts and DeadlinesFree lesson

Clock Skew and Time Synchronization

How clock drift between servers affects deadline accuracy and why monotonic clocks matter.

Clock Skew and Time Synchronization

You'll learn how clock drift between servers undermines deadline accuracy and why monotonic clocks are essential for reliable timeout behavior.


The Clock Drift Problem

When you propagate a deadline like "complete by 15:30:45 UTC," you assume all servers agree on what time it is. But server clocks drift independently—one might be 200ms ahead, another 500ms behind. When Server A sends a 1-second deadline to Server B whose clock is 300ms slow, Server B thinks it has 1.3 seconds. If Server B's clock is 300ms fast, it panics thinking only 700ms remain.

This clock skew breaks deadline propagation. Your carefully calculated timeout budgets become meaningless when clocks disagree.

Wall-Clock vs Monotonic Time

Wall-clock time (system time) can jump backward due to NTP corrections, leap seconds, or admin changes. If you calculate deadline - now() and the clock jumps back 2 seconds mid-request, your remaining time suddenly increases—absurd for a countdown.

Monotonic clocks never go backward. They measure elapsed time from an arbitrary starting point (like server boot). For timeouts and deadlines, always use monotonic time locally. When you receive a deadline timestamp from another service, immediately convert it to your local monotonic clock: local_deadline = monotonic_now() + remaining_seconds.

Mitigating Clock Skew

  • NTP synchronization: Keep clocks within ~100ms using protocols like NTP or PTP
  • Use relative timeouts: Propagate "seconds remaining" instead of absolute timestamps when possible
  • Monotonic clocks for local decisions: Never use wall-clock time for timeout math
  • Tolerate small skew: Add safety margins to deadlines (e.g., 50-100ms buffer)

Key Takeaway:
Clock skew between servers corrupts deadline accuracy; always use monotonic clocks for local timeout calculations and synchronize wall clocks with NTP to keep distributed deadlines meaningful.