Static

UUIDv7: Timestamps aren’t time-ordered and other oddities

First reported by Alexsci ·

The signal ●○○○ Compiled by AI from Alexsci and Hacker News
Why you might care

The timestamp embedded in UUIDv7 IDs can be arbitrarily inaccurate, breaking assumptions about creation time sorting.

What happened

A recent analysis of the UUIDv7 standard reveals that common assumptions about its properties, such as strictly time-ordered and unguessable IDs, are not always met by compliant implementations. The embedded timestamp, intended to denote creation time and aid in sorting, can deviate significantly from the actual generation time due to RFC 9562 allowing alterations for monotonicity. Implementations like Python's `uuid.uuid7()` can advance timestamps far beyond the system clock if the clock jumps backward or under heavy load, leading to non-time-ordered IDs. Furthermore, the claim of strictly monotonic IDs is mathematically impossible across distributed systems due to clock synchronization challenges, and even single-node implementations may fail to maintain strict order. The only guaranteed property across all implementations is collision resistance and uniqueness. The article highlights that users should not assume these ideal properties hold true and must question the specific guarantees and limitations of their chosen UUIDv7 implementation.

What it means

Implementations of UUIDv7 are permitted to manipulate the timestamp field, deviating from the actual creation time to maintain rough ordering. This divergence can become extreme when system clocks jump backward or under high generation load, leading to timestamps that are significantly ahead of real-time. Developers relying on UUIDv7 for precise temporal ordering or as a substitute for a dedicated creation timestamp column may encounter unexpected behavior and sorting anomalies.

The theoretical impossibility of strictly time-ordered IDs across distributed systems, a known challenge since the 1970s, is a fundamental limitation that UUIDv7 does not overcome. While implementations aim for rough ordering, the specification's claims can be misleading. Users must investigate the specific guarantees and constraints of their chosen UUIDv7 library, as variations in timestamp accuracy, counter behavior, and clock synchronization can lead to unpredictable ID sequences and potential data integrity issues.

AI-written summary. May contain errors.

Timestamps