Zenaique

Explain why clock skew across services produces 'negative duration' spans and how to handle it

Flashcard·Hard·4.0 · 0·~30s·Asked atDatadogDecagonStripe
Attempt it
TL;DR

Each service stamps spans with its own wall clock. Even tens of milliseconds of NTP drift can flip child versus parent ordering. Backends clamp negative durations and rely on parent-span ids for the tree.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Imagine two friends watching a relay race from different stadiums, each timing the runners with their own watch. If their watches disagree by half a second, the friend at the second stadium might record the second runner starting before the first finished, even though they did not. The race tree is still right (everyone agrees who handed off to whom), but the times look wrong. Fix the watches with NTP, and trust the handoff record over the watches when they disagree.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

Clock skew is one of those topics that looks like a bug but is actually a property of distributed systems. Every machine in your fleet has its own clock, those clocks drift relative to each other, and NTP or chrony keeps them close but never identical. Tracing across services means stitching together timestamps from different clocks, and when those clocks disagree, the trace shows artifacts: a child span appears to start before its parent, or a span has a negative duration.

This deep dive walks through why the artifacts happen, what OpenTelemetry's design does to make the trace usable anyway (parent_span_id is the load-bearing piece), how backends cope at render time, the operational discipline that keeps the artifacts small and rare, and when you would actually need a hardware clock instead of NTP.

Mental model: timestamps lie a little; ids do not. Order the tree by parent_span_id, clamp negative durations at render, alert on host-clock offset, and accept tiny negative durations as a known property of distributed time.

Why timestamps disagree across services

The root cause is simple and physical.

Every process uses its local wall clock

When a span starts, the SDK records the start time as 'whatever the operating system's wall clock says right now'. The OS gets this from the hardware clock, periodically corrected by NTP or chrony. The corrected value is close to UTC but not exact.

Cross-machine clocks differ

Machines A and B do not share a clock. Each has its own hardware oscillator, its own NTP daemon, and its own correction history. At any given moment, A's wall clock and B's wall clock might differ by a few milliseconds.

The OS clock is not monotonic across NTP adjustments

NTP can step the clock backward when the local clock is too far ahead of true time. The step is instantaneous. If a span on machine B starts before the step and ends after the step, the recorded end time can be earlier than the recorded start time, producing a negative duration without any physical violation of causality.

What 'normal' looks like

A healthy cluster with chrony or systemd-timesyncd typically holds skew under 10 to 50ms. Cloud VMs across the same region usually hit 1 to 5ms. Cross-region or cross-cloud traces can see 50 to 200ms skew. None of these are bugs; they are operating points.

What 'broken' looks like

Skew over 200ms across hosts in the same datacenter indicates NTP failure: the daemon is dead, the upstream server is unreachable, or the host's hardware clock has a fault. The downstream effects are wider than just traces; security tokens, distributed locks, and log ordering can all break.

How OpenTelemetry stays robust despite this
Operational discipline: monitor, alert, accept
When you need a hardware clock instead
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.

Real products, models, and research that use this idea.

  • AWS, GCP, and Azure all document host-clock drift as a known issue across VM live migrations and cold starts in their tracing best-practices guides.
  • Datadog, Honeycomb, and Tempo all clamp negative-duration spans at render time and emit a warning event rather than failing the trace.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QHow would you monitor clock skew across the fleet?
A

Run chrony on every host, scrape its 'offset to server' metric to Prometheus, alert at 50ms warning and 200ms critical. Cross-check with periodic ping-based clock-skew probes to a known good reference.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Treating tiny negative durations as a real anomaly to debug. They are nearly always clock skew artifacts; the real anomaly is anything more than a few hundred milliseconds, which means NTP is broken.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • Why each service stamps spans with its own wall clock

  • How network latency and clock offset interact to produce inverted timestamps

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Describe how end user thumbs up/down should flow back onto a trace
Flashcard·Easy