UUID / GUID v4 & v7 Generator Online
Generate cryptographically secure UUID v4 (random) and time-ordered UUID v7 (RFC 9562) identifiers in bulk. Eliminate database B-Tree index fragmentation with zero remote telemetry.
Why UUID v7 is Superseding UUID v4 (RFC 9562)
A Universally Unique Identifier (UUID) is a 128-bit label used to uniquely identify database records across distributed clusters without requiring a central coordination authority. While UUID v4 has been the industry standard for decades, it introduces a severe structural flaw in relational databases (PostgreSQL, MySQL InnoDB, SQLite, and Microsoft SQL Server):
- Random Write Degradation: UUID v4 generates 122 bits of pure pseudorandomness. Because values are completely unordered, inserting rows into a B-Tree clustered index requires writing to random memory addresses.
- Database Buffer Cache Thrashing: Once table indexes exceed available RAM, every single insert requires an expensive random disk I/O seek, causing page splits and degrading write performance by up to 75% on high-throughput workloads.
- The UUID v7 Breakthrough: Formalized in RFC 9562, UUID v7 encodes a 48-bit Unix millisecond timestamp in the leading bits, followed by 74 bits of cryptographically secure randomness. UUID v7 values sort chronologically, preserving 100% sequential B-Tree append locality while retaining universal collision safety.
UUID v7 128-Bit Binary Layout (RFC 9562)
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | unix_ts_ms | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | unix_ts_ms | ver | rand_a | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |var| rand_b | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | rand_b | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
UUID v4 vs UUID v7 Database Benchmark (PostgreSQL & MySQL)
| Performance Characteristic | UUID v4 (Random) | UUID v7 (Time-Ordered) | Auto-Increment INT / BIGINT |
|---|---|---|---|
| B-Tree Index Insertion Speed | Degrades non-linearly past RAM size | Sequential Append (Fastest) | Sequential Append |
| Distributed Multi-Region Safe? | YES (Zero coordination) | YES (Zero coordination) | NO (Requires central DB lock) |
| Database Page Splits | High (50% average page fill) | Near Zero (95%+ compact pages) | Near Zero |
| Enumeration Attack Risk | Zero (Cannot guess next ID) | Low (Timestamp exposed; 74-bit random) | High (User IDs easily scraped) |
Production UUID Generation Snippets Across Languages
Native UUID Generation in Modern Tech Stacks
-- PostgreSQL 17+ (Native UUIDv7) CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; SELECT uuid_generate_v7(); // Node.js v20+ / Modern Browsers const uuidV4 = crypto.randomUUID(); # Python 3.12+ import uuid uuid_v4 = uuid.uuid4() // Go (Golang with google/uuid) import "github.com/google/uuid" id, _ := uuid.NewV7()
Frequently Asked Questions (UUID FAQ)
What is the mathematical probability of a UUID v4 collision?
A UUID v4 contains 122 bits of entropy (\( 2^{122} \) or \( 5.3 \times 10^{36} \) combinations). Based on the Birthday Paradox, you would need to generate 1 billion UUIDs every second for 85 consecutive years before experiencing a 50% probability of a single duplicate collision.
Does UUID v7 leak the exact timestamp a database record was created?
Yes. The first 48 bits of a UUID v7 encode the Unix epoch in milliseconds. If hiding transaction timing from public API clients is a critical business requirement, use UUID v4 for external customer-facing permalinks and UUID v7 for internal clustered database primary keys.
What is the difference between a UUID and a GUID?
There is practically no functional difference. UUID (Universally Unique Identifier) is the standard IETF term, while GUID (Globally Unique Identifier) is Microsoft’s implementation term. Both adhere to the identical 128-bit structure defined in RFC 4122 and RFC 9562.
The Complete RFC 9562 UUID Taxonomy: Versions 1 Through 8
Published in 2024, RFC 9562 comprehensively updated the UUID specification to address modern database clustering and distributed systems requirements:
| UUID Version | Mechanism | Time-Ordered? | Primary Limitation / Vulnerability | Modern Industry Status |
|---|---|---|---|---|
| UUID v1 | 60-bit Gregorian timestamp + MAC Address | Yes (Low bits first) | Leaks hardware MAC address; poor byte order for indexing | Deprecated / Legacy |
| UUID v3 | MD5 Hash over namespace + name | No | MD5 is cryptographically broken | Deprecated (Use v5) |
| UUID v4 | 122 bits of pseudo-randomness (CSPRNG) | No | Causes random B-Tree database page splits | Widely used; phasing out for DB keys |
| UUID v5 | SHA-1 Hash over namespace + name | No | Deterministic name mapping | Active for idempotent name hashing |
| UUID v6 | Reordered Gregorian timestamp + MAC | Yes | Transition standard; still relies on Gregorian epoch | Superseded by v7 |
| UUID v7 | 48-bit Unix Epoch ms + 74 bits Randomness | YES (Optimal) | Leaks millisecond timestamp | NEW GOLD STANDARD (RFC 9562) |
| UUID v8 | Custom vendor-specific implementation | Custom | Non-standard interoperability | Specialized proprietary architectures |
The 2026 Primary Key Showdown: UUID v7 vs ULID vs Snowflake vs NanoID
Engineering teams frequently evaluate alternative sorting identifier formats for distributed primary keys:
| Identifier System | Length / Encoding | Time-Ordered? | Native SQL UUID Type? | Key Advantage |
|---|---|---|---|---|
| UUID v7 (RFC 9562) | 36 chars (16 bytes binary) | Yes (Millisecond) | YES (Native 128-bit) | Universal database support; zero index fragmentation |
| ULID | 26 chars (Base32 Crockford) | Yes (Millisecond) | Stored as binary(16) | Compact, URL-friendly string representation |
| Twitter Snowflake | 19 chars (64-bit BIGINT) | Yes (Millisecond) | Stored as BIGINT | Fastest 64-bit integer performance; requires coordination server |
| NanoID | 21 chars (URL-safe string) | No (Random) | Stored as VARCHAR | Extremely compact for public URLs |
Zero-Downtime Migration Runbook: Upgrading PostgreSQL from UUIDv4 to UUIDv7
For existing PostgreSQL databases experiencing slow write throughput, migrate tables to UUID v7 without table locks:
PostgreSQL 16/17 Zero-Downtime Migration
-- Step 1: Install UUIDv7 generator function (built-in in PG17)
CREATE OR REPLACE FUNCTION uuid_generate_v7() RETURNS uuid AS $$
-- Extracts current Unix epoch ms and concatenates with CSPRNG bits
SELECT encode(
set_bit(
set_bit(
overlay(uuid_send(gen_random_uuid()) placing substring(int8send(floor(extract(epoch from clock_timestamp()) * 1000)::bigint) from 3 for 6) from 1 for 6),
52, 1
),
53, 1
),
'hex'
)::uuid;
$$ LANGUAGE sql VOLATILE;
-- Step 2: Update default column generation for subsequent inserts
ALTER TABLE orders ALTER COLUMN id SET DEFAULT uuid_generate_v7();
The Complete RFC 9562 UUID Taxonomy: Versions 1 Through 8
Published in 2024, RFC 9562 comprehensively updated the UUID specification to address modern database clustering and distributed systems requirements:
| UUID Version | Mechanism | Time-Ordered? | Primary Limitation / Vulnerability | Modern Industry Status |
|---|---|---|---|---|
| UUID v1 | 60-bit Gregorian timestamp + MAC Address | Yes (Low bits first) | Leaks hardware MAC address; poor byte order for indexing | Deprecated / Legacy |
| UUID v3 | MD5 Hash over namespace + name | No | MD5 is cryptographically broken | Deprecated (Use v5) |
| UUID v4 | 122 bits of pseudo-randomness (CSPRNG) | No | Causes random B-Tree database page splits | Widely used; phasing out for DB keys |
| UUID v5 | SHA-1 Hash over namespace + name | No | Deterministic name mapping | Active for idempotent name hashing |
| UUID v6 | Reordered Gregorian timestamp + MAC | Yes | Transition standard; still relies on Gregorian epoch | Superseded by v7 |
| UUID v7 | 48-bit Unix Epoch ms + 74 bits Randomness | YES (Optimal) | Leaks millisecond timestamp | NEW GOLD STANDARD (RFC 9562) |
| UUID v8 | Custom vendor-specific implementation | Custom | Non-standard interoperability | Specialized proprietary architectures |
The 2026 Primary Key Showdown: UUID v7 vs ULID vs Snowflake vs NanoID
Engineering teams frequently evaluate alternative sorting identifier formats for distributed primary keys:
| Identifier System | Length / Encoding | Time-Ordered? | Native SQL UUID Type? | Key Advantage |
|---|---|---|---|---|
| UUID v7 (RFC 9562) | 36 chars (16 bytes binary) | Yes (Millisecond) | YES (Native 128-bit) | Universal database support; zero index fragmentation |
| ULID | 26 chars (Base32 Crockford) | Yes (Millisecond) | Stored as binary(16) | Compact, URL-friendly string representation |
| Twitter Snowflake | 19 chars (64-bit BIGINT) | Yes (Millisecond) | Stored as BIGINT | Fastest 64-bit integer performance; requires coordination server |
| NanoID | 21 chars (URL-safe string) | No (Random) | Stored as VARCHAR | Extremely compact for public URLs |
Zero-Downtime Migration Runbook: Upgrading PostgreSQL from UUIDv4 to UUIDv7
For existing PostgreSQL databases experiencing slow write throughput, migrate tables to UUID v7 without table locks:
PostgreSQL 16/17 Zero-Downtime Migration
-- Step 1: Install UUIDv7 generator function (built-in in PG17)
CREATE OR REPLACE FUNCTION uuid_generate_v7() RETURNS uuid AS $$
-- Extracts current Unix epoch ms and concatenates with CSPRNG bits
SELECT encode(
set_bit(
set_bit(
overlay(uuid_send(gen_random_uuid()) placing substring(int8send(floor(extract(epoch from clock_timestamp()) * 1000)::bigint) from 3 for 6) from 1 for 6),
52, 1
),
53, 1
),
'hex'
)::uuid;
$$ LANGUAGE sql VOLATILE;
-- Step 2: Update default column generation for subsequent inserts
ALTER TABLE orders ALTER COLUMN id SET DEFAULT uuid_generate_v7();
Cryptographic Randomness & Entropy Analysis in Distributed UUID Generation
A standard Version 4 UUID contains 122 bits of pseudo-random entropy. The mathematical probability of two randomly generated UUID v4 values colliding is given by the birthday paradox approximation:
UUID Collision Probability Formula
p(n) ≈ 1 - exp(-n² / (2 × 2¹²²))
To have a one-in-a-billion (\(10^{-9}\)) chance of a single duplicate key collision, a distributed system would need to generate over 103 trillion UUIDs. Even at a generation velocity of 1 billion UUIDs per second, it would take approximately 3,260 years to reach this threshold.
| UUID / ID Standard | Bits of Randomness | Collision Horizon (\(p = 10^{-9}\)) | Randomness Source | Clock Dependency Risk |
|---|---|---|---|---|
| UUID v4 | 122 bits | 103 Trillion IDs | CSPRNG (OS Entropy) | Zero (Clock-independent) |
| UUID v7 | 74 bits random + 48 bits time | 2.7 Billion IDs / millisecond | CSPRNG + System Clock | Low (Monotonic sub-ms counter handles drift) |
| ULID | 80 bits random + 48 bits time | 4.3 Billion IDs / millisecond | CSPRNG + System Clock | Low (16-bit monotonic overflow) |
| NanoID (21 chars) | 126 bits | 206 Trillion IDs | CSPRNG (URL-safe alphabet) | Zero (Clock-independent) |
Hardware RNG vs CSPRNG: Operating System Entropy Exhaustion
When running containerized microservices in multi-tenant cloud environments (such as AWS ECS, Google Cloud Run, or Kubernetes pods), high-velocity UUID generation can theoretically starve the OS entropy pool if using legacy blocking interfaces like /dev/random.
- Linux Modern Non-Blocking CSPRNG: Modern Linux kernels (5.6+) utilize the ChaCha20-based
getrandom()system call, guaranteeing cryptographically secure random bytes without blocking once initialized, makingcrypto.randomUUID()safe for high-concurrency microservices. - Browser Web Cryptography API: In client-side web applications,
crypto.getRandomValues()feeds directly from the host operating system’s cryptographic provider (CryptGenRandom on Windows, arc4random on macOS, getrandom on Linux).