Layout

The first 48 bits are the Unix timestamp in milliseconds. Bits 48–51 hold the version (7). The next 12 bits are the variant plus random data, and the remaining 62 bits are random. In the canonical string, the timestamp occupies the first 8 hex digits and part of the second group.

text
01924f7a-1c3e-7abc-8def-0123456789ab
^^^^^^^^ ^^^^
timestamp  version 7
(48-bit ms)

Why time order matters for databases

B-tree indexes store keys in order. Random v4 keys insert at random positions, causing page splits and write amplification. v7 keys append near the end of the index, which is the same access pattern as an auto-incrementing integer — without leaking the row count.

The random suffix also prevents the “guess the next ID” problem that sequential integers have. You get monotonic-ish ordering with unpredictability.

Clock caveats

  • The timestamp is wall-clock milliseconds, not a monotonic counter. Clock skew can produce out-of-order IDs.
  • Multiple IDs in the same millisecond are ordered by their random suffix, not by true generation order.
  • A clock that jumps backwards can create IDs that sort before earlier ones; RFC 9562 suggests a monotonic counter in the random bits for strict ordering.

If your database requires strictly increasing keys, combine v7 with a sequence or use a ULID implementation that handles same-millisecond monotonicity.