Quick revision
The short answer
Not reliably. NTP keeps the wall clocks of different machines close, often within a millisecond inside a data center, but the offset can grow much larger after network trouble, VM pauses or misconfiguration, and corrections can make a clock jump, so two events closer together than that uncertainty cannot be ordered by timestamp, and the later one may even carry the smaller time. We use the monotonic clock (System.nanoTime in Java) for durations and timeouts on one machine, and logical clocks, a single leader's sequence numbers or clock-aware databases to order events across machines, keeping wall-clock times for display and rough ordering.
What to remember
In this answer, we saw that each server has a wall clock, synchronised by NTP and able to jump, and a monotonic clock that only moves forward. NTP keeps wall clocks close but cannot guarantee a bound: offsets grow after network trouble, VM pauses or misconfiguration, and corrections step or slew the clock, with leap-second smearing on top. So events closer than the clock uncertainty cannot be ordered by timestamp. We use the monotonic clock for durations, logical clocks, leader sequence numbers or clock-aware databases for ordering, and wall time for display.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Not reliably. NTP keeps the wall clocks of different machines close, often within a millisecond inside a data center, but the offset can grow much larger after network trouble, VM pauses or misconfiguration, and corrections can make a clock jump, so two events closer together than that uncertainty cannot be ordered by timestamp, and the later one may even carry the smaller time. We use the monotonic clock (System.nanoTime in Java) for durations and timeouts on one machine, and logical clocks, a single leader's sequence numbers or clock-aware databases to order events across machines, keeping wall-clock times for display and rough ordering.
Why this question is asked
Sorting events by timestamp is so natural that most code does it without a second thought: the newest update wins, the log lines are merged by time, the lock expires at 10:00:05. Every one of those assumes clocks on different machines agree. Interviewers ask this question because it separates engineers who know what clock synchronisation really promises from those who will build last-write-wins bugs into the next system. In this answer, we will recap the two kinds of clock a server has, see what NTP can and cannot guarantee, show how timestamps put events in the wrong order, and decide which clock to use for which job.
1A Quick Recap: Two Kinds of Clock
Every server has two clocks with different jobs. The time-of-day clock, or wall clock, tells us the date and time, such as 2026-11-13 10:00:05.123 UTC. In Java we read it with System.currentTimeMillis() or Instant.now(). It is synchronised with other machines by NTP, the Network Time Protocol, or a similar service such as chrony, and because it is corrected, it can jump forwards or even backwards.
The monotonic clock only moves forward. In Java it is System.nanoTime(). Its value has no meaning as a date; it might count nanoseconds since the machine booted. Its one promise is that a later reading on the same machine is never smaller than an earlier one, which makes it the right tool for measuring how long something took.
Notice that the wall clock difference can be wrong, even negative, if NTP corrected the clock while doWork() ran. The monotonic difference is always right, but only on this machine; comparing nanoTime values from two servers is meaningless.
2What Synchronisation Can and Cannot Guarantee
NTP measures the round trip to a time server and estimates the offset between the local clock and the server's. Inside a data center with good time servers, clocks typically agree within a millisecond or less. Across the internet, a few to tens of milliseconds is normal.
But this is a typical value, not a guarantee. The offset grows when the network to the time server is congested or asymmetric, when a VM is paused for live migration and resumes with a stale clock, when a host's oscillator drifts with temperature, or when the time daemon is misconfigured or stopped. Offsets of seconds or minutes happen in real fleets.
When the time daemon finds an offset, it corrects it in one of two ways. It can step the clock, jumping it to the right time at once, which may move it backwards. Or it can slew the clock, running it slightly fast or slow, by up to 500 parts per million with classic NTP, until the offset disappears; slewing is gentler but means the clock is wrong for a while. Leap seconds add one more twist: many providers smear them, spreading the extra second over hours, so the length of a second changes slightly during that period and differs from machines that do not smear.
3How Timestamps Put Events in the Wrong Order
Suppose server A's clock is 30 ms ahead and server B's is accurate. A user updates their profile on A at real time 10:00:00.000, stamped 10:00:00.030. Twenty milliseconds later, a second update reaches B at real time 10:00:00.020, stamped 10:00:00.020. The second update really happened later, yet it carries the smaller timestamp.
If the system resolves conflicts by last write wins, it keeps the first update and silently discards the second. Nobody sees an error; the user's latest change simply disappears. Any two events closer together than the clock uncertainty, here 30 ms, cannot be ordered by timestamp.
4 messages in order. Play them, or step through them one at a time.
Within the clock uncertainty, timestamps cannot be trusted for order.
4Which Clock for Which Job
For durations and timeouts on one machine, always use the monotonic clock. Retry backoff, request timeouts, rate limiters and lease durations measured locally should use System.nanoTime(), or java.time APIs built on a monotonic source, so that an NTP step cannot make a timeout fire early or never.
To order events across machines, do not compare wall clocks. Use logical clocks, such as Lamport or vector clocks, which order events by cause and effect; or sequence numbers from a single leader, like a database's log sequence number or a Kafka partition offset, which are ordered because one node assigns them; or databases designed to account for clock uncertainty, such as Spanner with its uncertainty intervals or CockroachDB with hybrid logical clocks and a maximum offset.
Wall-clock timestamps still have a place: showing users when something happened, approximate ordering in logs and dashboards, and retention rules where a few seconds do not matter. We just never let correctness depend on them.
| Job | Use | Why |
|---|---|---|
| Timeout, backoff, elapsed time | monotonic clock (nanoTime) | never jumps on this machine |
| Order events across machines | logical clock or leader sequence | follows cause and effect |
| Last-write-wins conflicts | versions or HLC, not raw wall time | skew silently loses writes |
| Show a time to a user | wall clock | it is the only one that is a date |
| Log correlation | wall clock plus trace ids | approximate order is enough |
5Follow-up questions
Does using a better time source such as PTP solve the problem?
It shrinks the uncertainty, from milliseconds to microseconds in good setups, but does not remove it, and a misbehaving node can still drift. Systems such as Spanner make the uncertainty explicit and wait it out, which only works because the bound is known and small.
Is Instant.now() safe for measuring elapsed time?
No, it reads the wall clock, so an NTP step during the measurement makes the result wrong. Use System.nanoTime() for elapsed time and Instant only to record when something happened.
Can the monotonic clock go wrong too?
It can pause while a VM is suspended and, on some platforms, may or may not count time during sleep, so it measures elapsed time as the machine saw it. It still never goes backwards, which is what timeouts need.
6Conclusion
In this answer, we saw that each server has a wall clock, synchronised by NTP and able to jump, and a monotonic clock that only moves forward. NTP keeps wall clocks close but cannot guarantee a bound: offsets grow after network trouble, VM pauses or misconfiguration, and corrections step or slew the clock, with leap-second smearing on top. So events closer than the clock uncertainty cannot be ordered by timestamp. We use the monotonic clock for durations, logical clocks, leader sequence numbers or clock-aware databases for ordering, and wall time for display.
Open with
No, not reliably. Each machine's wall clock is synchronised by NTP or chrony, which usually keeps clocks within a millisecond or so inside a data center, but that's a typical value, not a guarantee.
Then, if they want more
The offset can grow much larger after network problems, a VM pause or migration, drift, or a misconfigured time daemon. And when it's corrected, the clock is either stepped, which can jump it backwards, or slewed, which runs it slightly fast or slow for a while; leap seconds are usually smeared, which changes the length of a second too.
So if two events on different servers are closer together than the clock uncertainty, I can't order them by timestamp, and the later event may even carry the smaller time. With last write wins, that silently loses the newer update.
For durations and timeouts on one machine I use the monotonic clock, System.nanoTime in Java, because it never goes backwards, but its values mean nothing on another machine.
To order events across machines I use logical clocks like Lamport or vector clocks, sequence numbers assigned by a single leader, such as log offsets, or a database that accounts for clock uncertainty like Spanner or CockroachDB. Wall-clock timestamps I keep for display and approximate ordering in logs.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Can you order events from two servers by their wall-clock timestamps? Explain what clock...": https://scrivio-interview-library.netlify.app/architecture/distributed-systems/f0abaebc30/