UUID Version 7 (UUIDv7) is a new version of UUID that is time-based and combines the concepts of timestamps and random number generators to provide more orderly and efficient unique identifiers.
UUIDv7 is a new addition to the UUID specification, and its core feature is the combination of timestamps and incrementing counters to produce more orderly and efficient unique identifiers. The design of UUIDv7 takes into account temporal relevance and monotonicity, and its structure is divided into several fields, including:
This design allows for fast sorting and efficient searching, while the counter prevents duplicates and maintains the continuity of the generation order in the event of system clock regression.
UUIDv7 can be widely applied in various fields, such as unique identification of database records, identification of distributed system nodes, file naming, and tracking of log entries. Due to its time-based characteristics, it is particularly suitable for systems that need to operate or retrieve based on temporal order.
The structure of UUIDv7 is as follows:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| unix_ts_ms (48 bits) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ver (4 bits) | rand_a (12 bits) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| var (2 bits) | rand_b (62 bits) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
This structure gives UUIDv7 good temporal clustering within a certain period, meaning that the size of UUIDs generated within a range is always similar, which meets the requirements for primary keys, and the 74 bits of randomness also ensure very good randomness.
In summary, UUIDv7 provides a unique and orderly identifier by combining timestamps and random numbers, making it suitable for scenarios that require chronological order and high-concurrency generation of unique identifiers.