Quick revision
The short answer
The negative values come from the wall clock: Instant.now() follows the system clock, and when NTP or an operator steps it back between the start and the end reading, the difference goes negative, while a forward step inflates it. Durations of exactly one hour on one day point to a daylight saving or time zone bug, typically a start time kept as a LocalDateTime and compared across the DST change, or a host whose clock is an hour off. Within a process we measure with System.nanoTime or a Micrometer Timer.Sample, and across services we rely on distributed tracing, where each span is timed locally, plus NTP or chrony to keep hosts in sync.
What to remember
In this answer, we saw that Instant.now() reads a wall clock that NTP, chrony or an operator can step, so subtracting two readings gives negative or inflated durations, and that durations of exactly one hour on a single day point to DST and LocalDateTime conversions or a misconfigured host. Inside a process we measure with System.nanoTime or Micrometer's Timer.Sample, across services we use tracing spans that are each timed locally, we keep hosts synchronized and monitor their offset, and we store timestamps as Instant in UTC.
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.
The negative values come from the wall clock: Instant.now() follows the system clock, and when NTP or an operator steps it back between the start and the end reading, the difference goes negative, while a forward step inflates it. Durations of exactly one hour on one day point to a daylight saving or time zone bug, typically a start time kept as a LocalDateTime and compared across the DST change, or a host whose clock is an hour off. Within a process we measure with System.nanoTime or a Micrometer Timer.Sample, and across services we rely on distributed tracing, where each span is timed locally, plus NTP or chrony to keep hosts in sync.
Background to this question
Dashboards are only useful if their numbers can be trusted. A request-duration chart with negative values and a spike of requests that took exactly 3,600 seconds makes people doubt every other number on it, and it can trigger false alerts or hide real slowness. This debugging question checks whether we can read those two symptoms as clues, name the clock behaviour behind them, and design measurement that stays correct across machines. In this answer, we will recap how wall clocks behave, trace the negative values to clock steps, trace the one-hour values to time zone handling, fix measurement inside one process, and then handle durations that cross services and hosts.
1A Quick Recap of Wall-Clock Time
Instant.now() returns the current moment according to the machine's wall clock, the clock that tells the time of day. That clock is not a steady counter. The operating system keeps it close to real time with NTP, the Network Time Protocol, or chrony, a common NTP implementation on Linux. When the clock is only a little off, they slew it, which means running it slightly faster or slower until it agrees. When it is far off, for example after a virtual machine resumes from a pause or a host boots with a bad hardware clock, they step it, which means jumping straight to the right time, forwards or backwards. An operator can also set the clock by hand.
So the difference between two Instant.now() readings is the real elapsed time plus every correction made to the clock in between. Usually the correction is zero, which is why the bug hides for weeks.
2Why Some Durations Are Negative
In our service the start Instant is stored in the request when it arrives and the end Instant is taken when it completes. If the clock is stepped back by 800 ms while a 300 ms request is in flight, the end reading is earlier than the start reading.
Notice that a step forward produces the opposite symptom, a duration that is too large by the size of the step, and that is invisible on a chart because it just looks like a slow request. The negative values are the only part of the error we can see. If the start Instant is created on one host and the end on another, for example the start comes from a gateway and the end from a backend, the same thing happens permanently, because the two hosts' clocks are never perfectly equal. That difference is called clock skew.
3Why Some Requests Take Exactly One Hour
An error of exactly 3,600 seconds, on one particular day, is a strong clue. Clock steps from NTP are rarely a whole hour, but daylight saving time changes are exactly one hour and happen on one day. That points to a place where a time without a zone, a LocalDateTime, is turned into an instant using a zone, or the other way round.
A typical bug looks like this: some component records the start as a LocalDateTime in local time, for example in a header or a database column without a time zone, and later code converts it back to an Instant using a fixed offset or the wrong zone. During the night of the DST change the same local time can mean two different instants, or a local time may not exist at all, and the conversion picks the other one.
The other explanation worth checking is a host whose clock or time zone setting is wrong by an hour, which shows up as many requests through one host being off by the same amount. We can tell the two apart by grouping the bad rows by host and by date. If they cluster on the DST date across all hosts, it is the conversion bug; if they cluster on one host, it is that machine's configuration.
The lasting fix for both is the same rule: store timestamps as Instant, which is UTC, and never compute a duration from LocalDateTime values. A LocalDateTime is a wall-clock reading with no zone, and arithmetic on it ignores DST entirely.
4Measuring Correctly Inside One Process
When the start and the end happen in the same JVM, the duration must come from a monotonic clock, one that only moves forward and is never corrected. In Java that is System.nanoTime. Micrometer's Timer.Sample uses it for us and records the result as a metric with percentiles.
We still keep the start Instant if we want to show when the request happened, but we never subtract it from another Instant to get the duration. Timestamp from the wall clock, duration from the monotonic clock.
5Measuring Across Services
A request that passes through a gateway, an order service and a payment service cannot be timed with one monotonic clock, because each host has its own. Subtracting a start Instant on one host from an end Instant on another always includes the skew between them, which on well-run hosts is a few milliseconds and on badly run ones can be seconds.
Distributed tracing solves this by never subtracting across hosts. Each service measures its own span locally with its own monotonic clock and reports a start timestamp and a duration. The tracing backend, for example one fed by OpenTelemetry or Micrometer Tracing, then lays the spans out on a timeline. If skew makes a child span appear to start before its parent, the durations are still right; only the placement is slightly off.
7 messages in order. Play them, or step through them one at a time.
No duration is computed by subtracting timestamps taken on different hosts.
Hosts still need good time, because the start timestamps are used to order events and correlate logs. We run NTP or chrony everywhere and monitor the clock offset each host reports, alerting when it passes a threshold such as 100 ms.
6Follow-up questions
How large can clock skew between hosts be, and how would you monitor it?
With NTP or chrony working against nearby servers, hosts in one data centre usually agree within a few milliseconds, and cloud providers' own time services often do better. Without synchronization, ordinary hardware clocks drift by several seconds per day, and a VM that was paused or a host with a broken time daemon can be minutes off. We monitor it by exporting the offset that chrony or ntpd measures, through node_exporter's time collectors or chronyc tracking, and alerting on large offsets and on a daemon that has lost its time sources. Kubernetes nodes share the host clock, so we monitor at node level.
7Conclusion
In this answer, we saw that Instant.now() reads a wall clock that NTP, chrony or an operator can step, so subtracting two readings gives negative or inflated durations, and that durations of exactly one hour on a single day point to DST and LocalDateTime conversions or a misconfigured host. Inside a process we measure with System.nanoTime or Micrometer's Timer.Sample, across services we use tracing spans that are each timed locally, we keep hosts synchronized and monitor their offset, and we store timestamps as Instant in UTC.
Open with
Both symptoms come from using the wall clock for durations. Instant.now reads the time of day, and NTP or chrony steps that clock when it is off, or an operator or a VM resume moves it.
Then, if they want more
If the clock is stepped back while a request runs, end minus start goes negative; if it is stepped forward, the request looks slower by the size of the step, which nobody notices. If the start Instant comes from a different host than the end, clock skew between hosts is in every value.
The exactly-one-hour cases on one day look like daylight saving time: somewhere a start time is kept as a LocalDateTime, or converted with the wrong zone, and on the night of the change the local time maps to the wrong instant.
I would group the bad rows by host and date to separate that from a single host with a wrong clock or zone. To fix it, inside one process I measure with System.nanoTime, or better Micrometer's Timer.Sample, which is monotonic.
Across services I would not subtract timestamps from different machines at all; distributed tracing has each service time its own span locally and the backend assembles the trace. I would make sure every host runs NTP or chrony and alert on the measured offset, and I would store timestamps only as Instant in UTC and never compute durations from LocalDateTime.
About this answer
- Last updated
- 12 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 documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
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 "A dashboard of request durations, computed as Instant.now() at the end minus a start...": https://scrivio-interview-library.netlify.app/java/date-and-time/7d56852186/