What is a UUID? The Complete Guide to RFC 9562 and Modern Unique Identifiers

What is a UUID? The Complete Guide to RFC 9562 and Modern Unique Identifiers

S Par SectoJoy
7 min de lecture

A UUID (Universally Unique Identifier) is a 128-bit lab […]

TL;DR

Résumé rapide

  • A UUID (Universally Unique Identifier) is a 128-bit lab
  • A UUID (Universally Unique Identifier) is a 128-bit label standardized under the new RFC 9562 , which officially replaced RFC 4122 in May 2024.
  • Understanding RFC 9562: The Modern Standard for UUIDs

Processus éditorial

Relu par SectoJoy et publié le 7 mai 2026. Cet article est mis à jour lorsque les détails du produit, les exemples ou les consignes d'utilisation évoluent. Dernière mise à jour : 7 mai 2026.

SectoJoy

Je suis un développeur indépendant créant des applications iOS et web, avec un focus sur les produits SaaS pratiques. Je me spécialise en SEO basé sur l'IA, en explorant constamment comment les technologies intelligentes peuvent stimuler la croissance durable et l'efficacité.

A UUID (Universally Unique Identifier) is a 128-bit label standardized under the new RFC 9562, which officially replaced RFC 4122 in May 2024. While UUID v4 remains the go-to for random IDs, UUID v7 is now the 2026 industry standard for database primary keys because its time-ordered nature prevents B-tree index fragmentation and boosts performance.

Understanding RFC 9562: The Modern Standard for UUIDs

A Universally Unique Identifier (UUID) is a 128-bit number used to identify information across computer systems without needing a central authority to coordinate them. According to Wikipedia, the chance of two UUIDs being identical is so close to zero that it’s practically impossible. This lets different teams label data independently, knowing their identifiers won’t clash.

In May 2024, the Internet Engineering Task Force (IETF) published RFC 9562, retiring the old RFC 4122 standard. This update was a response to the demands of modern distributed systems, which needed IDs that are both unique and easy to sort chronologically. The new standard introduced three versions: v6, v7, and v8.

The Anatomy of a Modern UUID: Identifying Versions and Variants

You’ll usually see a UUID as a string of 32 hexadecimal characters, split into five groups by hyphens in an 8-4-4-4-12 pattern (like 550e8400-e29b-41d4-a716-446655440000).

The internal bit structure is defined by two key fields:

  • Version bits: Found in the first four bits of the 7th byte. This digit—the first character of the third group—tells you which algorithm was used (for instance, “4” means v4, and “7” means v7).
  • Variant bits: Located in the 9th byte. As SnapUtils points out, modern RFC 9562 UUIDs use a 10 bit pattern, which separates them from older Apollo or Microsoft formats.

UUID 结构拆解示意图

Why UUID v7 is the New Gold Standard for Databases?

The biggest drawback of the popular UUID v4 is that it is completely random. When you use a random ID as a primary key in a B-tree Index, the database has to insert new rows into unpredictable spots. According to CreateUUID, this causes “page splits,” forcing the database to move data around to make room. The result is slower writes and inefficient memory use.

UUID v7 fixes this by putting a 48-bit Unix Epoch timestamp (accurate to the millisecond) at the start of the ID. This makes the IDs “time-ordered” or monotonically increasing. Since new IDs are always larger than old ones, the database can simply add them to the end of the index. This gives you the performance of a sequential integer while keeping the global uniqueness of a UUID.

UUID v4 随机插入 vs UUID v7 顺序插入的对比

Performance and Reliability

UUID v7 is reliable because it balances time with entropy. It uses a CSPRNG (Cryptographically Secure Pseudo-Random Number Generator) to fill the remaining 74 bits.

According to Wikipedia, the odds of a collision are incredibly low. You would have to generate about 1 billion UUIDs every second for 85 years just to reach a 50% chance of a single overlap. For almost any global application, UUID v7 is effectively collision-proof.

Database Storage Matrix: Binary(16) vs. String(36) Performance

How you store these IDs matters as much as the version you choose. SnapUtils suggests that developers should always use native types instead of strings when possible.

Storage Format Space Occupied Index Performance Recommendation
Binary(16) 16 bytes High (Compact) Best Practice
Native UUID 16 bytes High (Optimized) Best (PostgreSQL)
String (Char 36) 36-72 bytes Low (Fragmented) Avoid

In PostgreSQL, the native uuid type is the way to go. It stores data in a compact 16-byte binary format but still lets you run standard string-based queries.

UUID vs GUID: Is There a Difference?

Strictly speaking, a GUID (Globally Unique Identifier) is just Microsoft’s version of the UUID standard. In the past, there was a technical difference in “endianness”—the way bytes are ordered. SnapUtils explains that early Microsoft GUIDs used little-endian order for the first three fields, while standard UUIDs used big-endian (network byte order).

By 2026, these differences are mostly a matter of naming. Under RFC 9562, they work the same way. A Guid.NewGuid() in .NET is compatible with a uuid.uuid4() in Python. You’ll still hear “GUID” in Windows and Azure circles, while “UUID” is the preferred term in Linux and open-source communities.

Implementing Modern UUIDs: Code and Standards

Most modern libraries are already moving toward RFC 9562.

  • Python: The built-in uuid module handles v4 and v5. For v7, you’ll currently need the uuid6 or uuid7 packages.
  • JavaScript (Node.js/Browser): You can use crypto.randomUUID() for v4. For v7, the uuid npm package (v10+) is the standard choice.
  • PostgreSQL: Version 13+ includes gen_random_uuid() for v4. Newer versions (PG 17+) and various extensions now offer native uuidv7() functions.

Deterministic IDs: UUID v5 and Namespaces

If you need to generate the same ID every time for a specific piece of data—like a URL or a username—use UUID v5. It hashes a Namespace UUID and a name string using SHA-1. This is perfect for deduplication when you can’t check a central database.

The Legacy of UUID v1: Privacy Risks

UUID v1 uses a timestamp and the computer’s MAC address. This version has mostly been abandoned because it leaks hardware information. A famous example is the Melissa Virus creator, who was caught because the UUIDs in his infected Word documents contained his specific MAC address.

Best Practices for Rust and Go Developers in 2026

In performance-heavy languages like Rust and Go, UUID v7 is now the default for microservices. The uuidx package for R, which runs on a Rust backend, shows how the industry is shifting toward Rust’s uuid crate (v1.7+) to ensure thread-safe, high-entropy ID generation.

Advanced RFC 9562 Features: v6, v8, and Special UUIDs

RFC 9562 added specialized versions for specific distributed system needs:

  • UUID v6: This is a reordered v1 timestamp. It keeps the high precision of v1 but makes the bits sortable, serving as a bridge for older systems that aren’t ready for v7.
  • UUID v8: This is the “custom” version. It offers 122 bits that developers can use for their own experimental or vendor-specific data, as long as they follow the standard version and variant rules.
  • Special Values:
    • Nil UUID: 00000000-0000-0000-0000-000000000000 (all zeros), often used as a null placeholder.
    • Max UUID: FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF (all ones), used to mark the end of a range or list.

Conclusion

RFC 9562 has updated unique identifiers for the modern cloud era. UUID v7 is the clear winner for database apps, while v4 remains perfectly fine for general randomness. By moving away from the old RFC 4122 standard, developers can finally get both global uniqueness and fast database performance without the “random insert” slowdown.

Actionable Advice: Check your database schemas. If you’re using UUID v4 as a primary key in tables with millions of rows, consider migrating to UUID v7. It’s a straightforward change that can significantly reduce index fragmentation and speed up your PostgreSQL or MySQL instances.

FAQ

Is a UUID the same as a GUID?

Technically, a GUID is Microsoft’s implementation of the UUID standard. While they are used interchangeably today, historically they differed in byte-ordering (endianness) during binary serialization. Under RFC 9562, they are functionally identical for most developers, and you can use them interchangeably in modern .NET, Java, or Python applications.

Can two UUIDs ever collide in a real-world scenario?

While mathematically possible, it is practically impossible. For UUID v4, you would need to generate approximately 2.71 quintillion IDs to reach a 50% collision probability. According to Generate-Random.org, generating 1 billion UUIDs per second for 85 years would only result in a 50% chance of a collision, assuming a high-quality CSPRNG is used.

Should I store UUIDs as strings or binary in my database?

You should always prefer Binary(16) or the native UUID type (available in PostgreSQL). Storing a UUID as a 36-character string consumes more than twice the space and significantly slows down index lookups and joins. SnapUtils notes that the performance benefits of RFC 9562 are most effective when storage remains compact.

When should I use UUID v5 instead of UUID v4?

Use UUID v5 when you need “deterministic” IDs—meaning the same input (like a URL) must always produce the same output ID without a central database lookup. Use UUID v4 when you need complete randomness and want to ensure that the identifier cannot be linked back to the input data or the system that generated it.

Questions fréquentes

Why UUID v7 is the New Gold Standard for Databases?

The biggest drawback of the popular UUID v4 is that it is completely random. When you use a random ID as a primary key in a B-tree Index, the database has to insert new rows into unpredictable spots. According to CreateUUID, this causes “page splits,” forcing the database to move data around to make room. The result is slower writes and inefficient memory use. UUID v7 fixes this by putting a 48-bit Unix Epoch timestamp (accurate to the millisecond) at the start of the ID. This makes the IDs “time-ordered” or monotonically increasing. Since new IDs are always larger than old ones, the database can simply add them to the end of the index. This gives you the performance of a sequential integer while keeping the global uniqueness of a UUID.

UUID vs GUID: Is There a Difference?

Strictly speaking, a GUID (Globally Unique Identifier) is just Microsoft’s version of the UUID standard. In the past, there was a technical difference in “endianness”—the way bytes are ordered. SnapUtils explains that early Microsoft GUIDs used little-endian order for the first three fields, while standard UUIDs used big-endian (network byte order). By 2026, these differences are mostly a matter of naming. Under RFC 9562, they work the same way. A Guid.NewGuid() in .NET is compatible with a uuid.uuid4() in Python. You’ll still hear “GUID” in Windows and Azure circles, while “UUID” is the preferred term in Linux and open-source communities.

Is a UUID the same as a GUID?

Technically, a GUID is Microsoft’s implementation of the UUID standard. While they are used interchangeably today, historically they differed in byte-ordering (endianness) during binary serialization. Under RFC 9562, they are functionally identical for most developers, and you can use them interchangeably in modern .NET, Java, or Python applications.

Can two UUIDs ever collide in a real-world scenario?

While mathematically possible, it is practically impossible. For UUID v4, you would need to generate approximately 2.71 quintillion IDs to reach a 50% collision probability. According to Generate-Random.org, generating 1 billion UUIDs per second for 85 years would only result in a 50% chance of a collision, assuming a high-quality CSPRNG is used.

Should I store UUIDs as strings or binary in my database?

You should always prefer Binary(16) or the native UUID type (available in PostgreSQL). Storing a UUID as a 36-character string consumes more than twice the space and significantly slows down index lookups and joins. SnapUtils notes that the performance benefits of RFC 9562 are most effective when storage remains compact.

Articles associés