Lesson 1 of 13 · 16m
Clocks Are Lying to You
Wall-clock timestamps cannot order events across machines, because NTP is allowed to move your clock backward.
Every timestamp your system writes came from a clock a daemon is actively rewriting. On Linux, clock_gettime(CLOCK_REALTIME) returns wall time — the number chrony or systemd-timesyncd believes UTC to be — and NTP is permitted to slew it, step it, and, on a leap second, play an entire second twice. When the offset is larger than about 128 ms, ntpd steps the clock: the value jumps. It can jump backward. CLOCK_MONOTONIC is the other clock the kernel gives you: never stepped, never leap-adjusted, only rate-corrected. It is the right source for measuring intervals and the wrong source for comparing notes with another machine, because its epoch is arbitrary.
Java exposes the same split. System.currentTimeMillis() is realtime. System.nanoTime() is a monotonic source for measuring elapsed time and nothing else — its origin is not meaningful and is not the same on two processes, let alone two hosts.
The wrong mental model
The assumption is that a timestamp answers the question "which event happened first?" Across a network it cannot. Two NTP-disciplined servers commonly disagree by tens of milliseconds, and that disagreement is not bounded by anything you control — a congested upstream, a lost symmetric key, a leap smear, a VM restored from snapshot. Causality is a partial order that clocks approximate badly.
What this breaks in production is conflict resolution. "Last write wins" resolves two concurrent writes by comparing their wall-clock timestamps. Cassandra lets you supply USING TIMESTAMP, and older clients genuinely did. Now picture a client whose clock runs 200 ms ahead writing a tombstone, or a node ahead-of-time deleting a value a slower node writes "earlier." The system does not report an error. It silently keeps the wrong value. The data loss has no log line in it.
The real world already demonstrated this
June 30, 2012, a leap second was inserted into UTC. The Linux kernel's hrtimer code had a livelock bug around leap adjustment, and applications using CLOCK_REALTIME saw the clock jump — the classic "one second happened twice" problem that breaks any code which assumed time moves forward. Reddit, LinkedIn, Mozilla, and a long tail of Java stacks pegged CPUs at 100%. Google's fix for the next leap second was the leap smear: lie to the fleet deliberately, spreading the extra second across the day in milliseconds, because a controlled lie beats an uncontrolled jump.
Spanner went further and made uncertainty explicit. TrueTime exposes TT.now() as an interval, not a point — GPS receivers and atomic clocks per datacenter keep the half-width epsilon in the single-digit milliseconds — and commit-wait literally sleeps out the interval before acknowledging a write. CockroachDB gets most of the same ordering benefit without atomic clocks using hybrid logical clocks, but it has to make the opposite trade: if a node's offset exceeds --max-offset (default 500 ms), the process exits. The system would rather kill a node than let its clock order writes.
Logical clocks exist for the same reason. A Lamport clock guarantees a -> b implies L(a) < L(b), but the converse is false — L(a) < L(b) does not prove a caused b. Vector clocks pay more metadata to detect concurrency rather than hide it.
What to actually do
Measure durations with a monotonic clock only: clock_gettime(CLOCK_MONOTONIC), System.nanoTime(), Go's time.Since (monotonic-aware since Go 1.9). Treat stored wall timestamps as data about an event, not truth about its order. Order events with sequence numbers that exist because they order things: Kafka offsets, Postgres WAL LSNs, etcd revisions, Raft log indices. When a caller supplies a timestamp for anything security- or correctness-relevant — token expiry, write conflict, retry dedup windows — do not use their clock. Alert on NTP offset; a node with 500 ms of skew is a correctness bug in waiting.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
What is Platform as a Service? The Sweet Spot Between "Too Easy" and "Too Much Work"
Platform as a Service sits between raw servers and fully managed software. You push code, the platform runs it. No Nginx config, no OS patches, no 3 AM server alerts. Here is what PaaS actually gives you, what it costs you in control, and how to decide if it is the right layer for your application.
The World now is Serverless and Container based
A new report from Datadog reveals that serverless computing could be entering the mainstream. This has already been the case in my world for the past few years. Results show that more than half of all organizations are using serverless on one of the three major public cloud providers: Amazon,
AWS Emulator Puts AWS on Your Laptop. Keep Your IAM Tests Off It.
AWS released AWS Emulator on November 11, a free local server that answers AWS API calls on 127.0.0.1 with per-run keys and fresh certificates.
A 257-Byte Password Is the Key: Inside the OpenSSH musl Bypass
CVE-2026-123158 lets an attacker log into a locked account on musl-based systems like Alpine by sending a password nobody set. The trigger is one number, 257, and the reason is a C library returning a single asterisk. I reproduced the exact boundary against musl 1.2.4 and read the fix.