UUID Generator
Generate universally unique identifiers (UUIDs). Choose between the random v4 standard or the new, time-based, and sortable v7 standard.
A Universally Unique Identifier (UUID) is a 128-bit number used to identify information in computer systems. When generated according to the standard methods, UUIDs are, for all practical purposes, unique. Their uniqueness does not depend on a central registration authority or coordination between the parties generating them, unlike most other numbering schemes.
UUIDs are a fundamental building block in modern software development, commonly used as primary keys in databases, transaction IDs, and unique identifiers for almost any resource.
Version 4 (Random)
UUIDv4 is the most common version. It is generated using 122 bits of purely random or pseudo-random numbers. Because they are random, they have no inherent order and are excellent for ensuring uniqueness without leaking any information about the time or location of their creation.
- Pros: Extremely high collision resistance, simple to generate, reveals no information.
- Cons: Not sortable by creation time, which can lead to database index fragmentation and slower write performance in some database systems (like PostgreSQL).
Version 7 (Time-based)
UUIDv7 is a new standard (published in 2024) designed to address the shortcomings of v4 for database primary keys. The first 48 bits are a Unix timestamp (milliseconds since 1970), followed by 74 bits of random data. This makes them time-ordered and k-sortable.
- Pros: K-sortable by time, which is highly efficient for database indexing (prevents fragmentation). Includes a timestamp component for free. Still has very high collision resistance due to the random bits.
- Cons: Leaks the creation time of the record, which might be a security concern in some specific applications. It is a very new standard and may not be supported by all libraries out of the box.
Which one should I use?
For general-purpose unique IDs where sorting is not a concern, **v4** is a safe, standard choice. For new projects using UUIDs as database primary keys, **v7** is increasingly recommended for its performance benefits.