A UUID (Universally Unique Identifier) is a 128-bit identifier that is unique across both space and time. It is commonly used in software development for various purposes, such as uniquely identifying entities.
There are five productive versions of UUIDs:
The Version 4 is the most used UUID version because the UUIDs are randomly generated.
A UUID is typically represented as 32 hexadecimal digits, displayed in five groups separated by hyphens: 550e8400-e29b-41d4-a716-446655440000xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx the UUI version can be identified by looking at the 13th digit (M) of the Hexadecimal UUID string. If then digit M is 1 then the UUID is version 1, if M is 3 then the UUID is version-3, etc.
There is also a “variant” and the 17th (N) digit represents it in hexadecimal:Binary | Hex Digit | Variant |
---|---|---|
0xxx | 0 - 7 | reserved (NCS backward compatible) |
10xx | 8 - b | DCE 1.1, ISO/IEC 11578:1996 |
110x | c - d | reserved (Microsoft GUID) |
1110 | e | reserved (future use) |
1111 | f | unknown / invalid. Must end with "0" |
UUID version 1 is generated based on the current timestamp and node (usually the MAC address). It's suitable for scenarios where time-based ordering is important, such as in distributed systems.
UUID version 4 is generated using random or pseudo-random numbers. It's suitable for scenarios where uniqueness is more critical than time-based ordering.
UUID versions 3 and 5 involve hashing a namespace identifier and a name to create a UUID. The namespace provides a way to avoid collisions between different sets of names.
The probability of generating the same UUID is extremely low, especially for version 4 UUIDs that use random numbers. However, it's not impossible, and precautions should be taken in critical applications. For instance, with UUID version 4, the chance of generating a duplicate is about 1 in 5.3x10^36.
Valid UUIDs adhere to the specified format. You can use regular expressions or this app to validate a UUID and determine its Version.
While UUIDs are not designed for cryptographic security, they can be used as identifiers. For security-sensitive applications, additional measures such as encryption should be considered.
While UUIDs may have a slightly higher storage overhead compared to sequential integers, modern databases are optimized to handle UUIDs efficiently. Considerations may vary based on the specific use case and database system.
UUID (Universally Unique Identifier) and GUID (Globally Unique Identifier) are often used interchangeably. UUID is more commonly used in the context of open standards, while GUID is commonly associated with Microsoft technologies.
Yes, UUIDs can be used as primary keys. They provide advantages in distributed systems and scenarios where uniqueness across systems is crucial. However, they are larger and can, in certain environments, be less efficient than traditional incremental IDs.
Yes, you can store UUIDs as strings or binary data in databases that do not have native UUID support. Be sure to use a consistent format and handle conversions appropriately.
While UUIDs are not intended for cryptographic security, they can be used as identifiers in secure systems. For cryptographic purposes, additional measures, such as proper key management, are recommended.
Common mistakes include assuming UUIDs are ordered or time-based, using UUIDs as security tokens, and inefficient storage or indexing in databases.
In UUID version 1, the timestamp is a 60-bit value representing the number of 100-nanosecond intervals since midnight, October 15, 1582 UTC. This is combined with clock sequence and node (MAC address) information.
Yes, UUIDs can be used in URLs. Normally, UUIDs do not require special URL encoding as they consist of hexadecimal characters and hyphens, which are safe in URLs. UUIDs are not human-readable or memorable, which can be a downside in user-facing URLs. However, for machine-to-machine communication, this is not an issue.