# When do equal timestamps make replay order non-deterministic? **Date of Record:** 2026 November 1 **Scope:** Applies to event logs ordered by a timestamp whose resolution is coarser than the event rate, when replay or state reconstruction depends on order. Excludes logs with a monotonic sequence as the primary order. ## Core Distinction **Predicate.** Deterministic replay requires a total order on events. A timestamp provides a total order only if no two events share a value, or if the ordering rule breaks ties deterministically. If the order key is (timestamp) alone, and events collide at the resolution, replay order is whatever the storage layer returns, which may vary between runs, replicas, and index states. **Failure.** Two events share a millisecond. Their relative order determines the reconstructed state when they modify the same field. Replay on the primary and on a replica may apply them in different orders, producing divergent state from identical logs. **Asymmetry.** Each event is correct in isolation. Only the pair is ambiguous, and the ambiguity is invisible unless two replays are compared against each other. ## What Was Observed **Signature.** Reconstructed state differing between two replays of the same log. The divergence is rare, correlates with write bursts, and disappears on retry because the storage order happens to stabilize. Investigations that re-run the replay cannot reproduce the divergence. **Trace.** Two updates at the same millisecond to the same field. Log A stores them in insertion order; replica B returns them by an index that orders equal keys differently after a compaction. Replay on A yields value2, replay on B yields value1. Both replays process the same set of events. **Why monitoring stays green.** Log completeness checks pass. Event counts match. Each event applied without error. Divergence appears only as a downstream state difference that is attributed to something else. ## Condition of Validity Replay is deterministic only while at least one holds: 1. **Total order key.** The order key includes a tiebreaker that is unique and monotonic (sequence number, ULID, per-producer counter). 2. **Idempotent and commutative.** Events are applied such that order does not affect the result, verified rather than assumed. 3. **Single replay path.** Exactly one component replays, and its order is captured as part of the output so it cannot drift. Condition 2 is usually assumed and rarely verified for writes to shared fields. ## Decision Boundary - Unique monotonic key: deterministic replay. - Timestamp plus unique tiebreaker: deterministic, provided the tiebreaker is preserved through storage. - Timestamp alone at coarse resolution: non-deterministic when collisions occur on the same field. Treat as unsafe. - Timestamp alone plus commutative operations: safe for the operations proven commutative, unsafe for the rest. ## Operational Effect The defect is a property of the log's ordering contract, which is set at write time and relied upon at replay time by a different system. Remediation is to add a monotonic tiebreaker at the producer and preserve it through storage. The trap is to increase timestamp resolution. That lowers the collision rate without eliminating it, and it converts a reproducible defect into one that appears only under bursts, which is when replay matters most. ```python from dataclasses import dataclass class ReplayOrderError(RuntimeError): """Raised when the replay order key is not a total order over the event set.""" @dataclass(frozen=True) class ReplayOrderGate: order_key_fields: tuple events_commutative: bool = False def verify(self) -> bool: if self.events_commutative: return True if "timestamp" in self.order_key_fields and len(self.order_key_fields) == 1: raise ReplayOrderError( "timestamp alone is not a total order at coarse resolution" ) if not self.order_key_fields: raise ReplayOrderError("no order key: storage order will be used") return True def dispatch_replay_mode(gate: ReplayOrderGate) -> str: try: gate.verify() except ReplayOrderError: return "add-monotonic-tiebreaker" return "ordered-replay" ```