SEARCH THE LAB

What are you looking for?

ScienceReview information not provided

Same Millisecond, Different Moments: Why System Time Cannot Stand In for Event Order

Review information not provided · 3 min

Two log lines both carry the timestamp 12:00:00.123 — which happened first? Many people just sort by time and let the sorting algorithm handle the tie. That …

Same Millisecond, Different Moments: Why System Time Cannot Stand In for Event Order

Two log lines both carry the timestamp 12:00:00.123 — which happened first? Many people just sort by time and let the sorting algorithm handle the tie. That effectively treats “the measurement cannot tell them apart” as “they happened at the same time,” and those are not the same thing. Equal timestamps only say that there is no difference at this precision; they do not say the two events were truly simultaneous, and still less that there is no causal relationship between them.

A timestamp is a measurement: it has a resolution, and it has a point of collection. Millisecond- or even second-level logs compress many events into the same value. Rounding, truncation, batch writes, and multiple records in one transaction sharing a commit time all produce large numbers of equal values. In an audit log, two deletion records carry exactly the same time, and which came first cannot be answered; in an order system, payment and inventory deduction land in the same millisecond, and the timestamps alone cannot separate them. When a sorting algorithm meets equal keys, the order it produces is implementation-dependent: a stable sort preserves input order, an unstable sort may scramble it, and neither is a fact.

Across hosts the problem gets worse. NTP can only hold skew within a bounded range; network jitter, virtualization pauses, and heavy machine load all widen the error. Two machines may each look “in sync,” yet the true order can be the reverse of the timestamp order: an event that happened earlier on machine A can be written with a later time because A's local clock runs slow. Add log transport delay and buffering at the collector, and the timestamp may reflect not when the event happened but when it was written.

Clocks also go backwards. Step adjustments during synchronization, manual time changes, a virtual machine restored from a snapshot, and leap-second handling can all give a later event an earlier timestamp. Timestamps are not monotonically increasing, so using one as a sequence number rests on a premise that fails from the start. This is also why the kernel provides a monotonic clock, intended for measuring intervals rather than expressing calendar time.

Semantics are often overlooked too. Ingress receipt, entry into a queue, writing to disk, and transaction commit are four different moments; the same business operation recorded in different systems should not be expected to carry equal timestamps. Differences in time zone, precision, and format can also display different moments as the same string. Sorting timestamps from different sources in one table amounts to conflating several different measurements.

The distributed-systems conclusion is clear: a physical clock gives an approximate interval with error, and cannot establish causal order. To order events, you must record ordering information. A single-writer scenario uses a monotonic sequence number; a database uses the write-ahead log's LSN or a commit sequence; a message queue uses an offset; Lamport clocks judge causality across nodes, and vector clocks identify concurrency; when a global total order is needed, introduce a single sequencer or a consensus log. Hybrid logical clocks combine physical time with a logical counter and can narrow the uncertainty window, but they do not eliminate error, and you cannot infer true duration from them.

In practice, logs should record the source node, a monotonic counter, and the parent-child relationships of traces and spans. When investigating, reconstruct the causal chain first, then explicitly mark concurrent events with no causal relationship as “order unknown.” Do not treat a sort result as a conclusion, and above all do not casually add an id tiebreaker when timestamps are equal and then claim that is the true order.

The limitations should be stated plainly as well. Logical clocks do not reflect real duration; sequence numbers are valid only within the scope of one writer; vector clocks grow with the number of participants; and causal relationships that were never recorded cannot be reconstructed after the fact. Timestamps remain suitable for coarse-grained time windows, performance analysis, and “roughly simultaneous” judgments — they just cannot carry the ordering responsibility alone. Handing ordering to timestamps is asking a tool that can only measure an approximation to answer a question it cannot answer.

So the correct reading of equal timestamps is: at this precision, the order cannot be distinguished — not that the two events happened simultaneously. If you need order, ask whether the system recorded order; if it did not, honestly marking the order as unknown is more reliable than inventing one.