The CreateUuid7 method generates a unique 128-bit
value which uses the Version 7
UUID format as described in RFC 9562. It is a new
generation method designed to address limitations of older UUID
versions. Unlike Version 1 UUIDs, which also embed a timestamp but
expose MAC addresses and have coarse time granularity, Version 7 UUIDs
are privacy-preserving, forward-compatible, and use millisecond
resolution for broader applicability and improved precision.
Version 7 UUIDs are time-based identifiers that encode the number
of milliseconds since the Unix epoch (January 1, 1970 UTC) directly
into the high-order bits of the UUID. This provides a naturally
sortable identifier that preserves creation order and facilitates
efficient indexing, logging, and storage in systems that rely on
time-based sequencing.
The timestamp portion of a Version 7 UUID represents the number of
milliseconds since the epoch, encoded as an unsigned 48-bit integer.
This allows for chronological sorting of UUIDs without parsing or
inspecting the full binary payload. The remaining bits are randomly
generated using a secure system-level random number generator to
prevent collisions and ensure entropy across processes, machines, and
time intervals.
Version 7 UUIDs are particularly useful for:
- Generating IDs in web APIs, message brokers, and event logs
that must reflect creation time.
- Replacing monotonically increasing integers with sortable
UUIDs to avoid predictability.
- Designing database indexes that benefit from insertion-order
locality without needing sequential integer keys.
Note: Although Version 7 UUIDs are still in the draft standard
phase (RFC 9562), they are widely supported by modern tools. The UUIDs
produced by CreateUuid7 conform to the expected structure
and semantics defined in the RFC, ensuring forward compatibility with
future standards and implementations. This method generates the
timestamp using the internal system clock using the highest precision
possible. If the system clock is not synchronized with a time server,
this may cause time drift in the generated UUID.