exit code 0.5

Systems 6 min read

A Duplicate UUIDv4 Will Probably Happen in Your Lifetime

Conflating local operational safety with global mathematical impossibility—Birthday Paradox math, planetary throughput, and why domain isolation actually saves us.

Every backend developer has read some variation of this reassuring line in a tutorial or documentation page:

The Industry Myth: “If you generated a million UUIDs every second, it would take roughly 3,000 years to have a 50% chance of a single collision. You are more likely to be struck by a meteorite.”

It sounds comforting. It gives you that warm, fuzzy feeling of architectural safety. And mathematically, it’s a sleight of hand.

The point isn’t that UUIDs are broken or that you should rip them out of your stack tomorrow. They work great. But the way our industry talks about them is disingenuous. People conflate local operational safety with global mathematical impossibility by using tiny, vintage numbers to describe a planet-scale system.

Once you plug actual modern infrastructure throughput into the equation, the reality is stark: somewhere on Earth, a duplicate UUIDv4 is almost certainly going to be minted within a single human lifetime.

The 61-bit trap

A UUIDv4 is 128 bits long. RFC 4122 reserves 6 of those bits for metadata (4 bits for the version, 2 for the variant), leaving 122 bits of actual entropy.

That gives us a total state space of 2^122 ≈ 5.3 × 10^36 possible UUIDs.

That number is larger than the number of sand grains on Earth. When people see that, their human brains short-circuit and assume, “Cool, collisions are impossible.”

Except that’s not how probability works when things are generated independently. You don’t need to search through all 2^122 states to find a collision; you only need two independent draws to land on the same number.

Thanks to the Birthday Paradox, the number of draws N required to reach a 50% chance of at least one collision scales with the square root of the keyspace:

text
N ≈ √(2 · ln(2) · 2^122) ≈ 1.177 × 2^61 ≈ 2.71 × 10^18

Just like that, your 122 bits of protection collapse into an effective 61 bits of collision resistance.

2.71 quintillion is still a massive number. In 1995, when distributed systems meant three servers talking over a LAN, running through 2^61 states was an eternity. But we don’t live in 1995 anymore.

Running the planetary math

Think about how many UUIDv4s are actually minted across global infrastructure every second.

We aren’t talking about your local monolithic app inserting a few rows into a staging database. We’re talking about the aggregate reality of global computing:

  • The Edge: Cloudflare alone handles tens of millions of HTTP requests per second. Add Akamai, AWS CloudFront, Fastly, and custom NGINX edge layers, and public ingress is easily pushing hundreds of millions of requests per second.
  • Microservice Fan-Out: A single public API call routinely fans out into 10 to 30 internal RPC calls. Even when teams use raw hex for OpenTelemetry spans, massive amounts of internal routing headers, idempotency keys, and message queue envelopes (Kafka, RabbitMQ, SQS) generate UUIDv4s on the fly.
  • Database Writes: Millions of PostgreSQL, MongoDB, and DynamoDB instances across millions of companies globally are constantly executing gen_random_uuid() for primary keys.
  • Client Telemetry: Billions of mobile apps and browser sessions minting local IDs for crash reporting, session replays, and analytics payloads.

A conservative, realistic baseline for global UUIDv4 production across all datacenters, devices, and clouds easily sits at 1 billion UUIDs per second (10^9/sec). If you count every transient debug span and log trace, it’s likely even higher.

Now run the simple division:

text
Time to 50% collision = (2.71 × 10^18 UUIDs) / (10^9 UUIDs/sec)
                      ≈ 2.71 × 10^9 seconds
                      ≈ 86 years

That’s not the heat death of the universe. That’s not 3,000 years. That is one human lifespan.

If the global generation rate climbs to 10 billion per second as IoT and autonomous systems expand, that window drops to under 9 years.

Why the internet hasn’t broken

If a duplicate UUIDv4 is statistically bound to happen in our lifetime, why hasn’t everything collapsed into a smoking pile of unique constraint errors?

Because the safety of UUIDs never actually came from the keyspace being untouchable. It comes from domain isolation.

If an autonomous tractor in Iowa generates an event with ID 4a8f... and writes it to an isolated SQLite log, and thirty years later an inventory database for a retail chain in Tokyo inserts a record with that exact same 4a8f..., the mathematical collision happened. But the systems never touch.

They will never share a memory space, they will never sit in the same B-tree index, and they will never throw a uniqueness error. The collision is purely existential—it happened in the void, completely unnoticed, because the global state space is shattered into hundreds of millions of private, unlinked silos.

Why the “impossible” myth is dangerous

If domain isolation saves us anyway, why does calling collisions “impossible” matter?

Because when engineers believe an abstraction is physically infallible, they stop respecting its boundaries.

  • The “Clean URL” Blunder: Developers look at a 36-character UUID string, decide it looks ugly in an email link, and truncate it to the first 8 or 12 characters. The moment you chop a UUID down to 48 bits, the 50% birthday collision bound plummets to roughly 16 million items (2^24). That is an afternoon of data on a moderately busy service.
  • Merging Without Scoping: Teams merge datasets from acquired companies or multi-tenant shards without adding a tenant or namespace prefix, assuming that “UUIDs can never collide across systems.”
  • The UUIDv7 Migration Trap: Modern distributed databases hate UUIDv4 because fully random keys destroy B-tree index locality and cause massive cache thrashing on writes. The industry is currently rushing to adopt UUIDv7, which prefixes a 48-bit millisecond timestamp to make IDs sequential.

That fix solves disk thrashing, but it trades away entropy: UUIDv7 drops the random component down to 74 bits.

If you have a hyper-scale, distributed ingest pipeline generating IDs within the exact same millisecond, your collision boundary is no longer 2^61. It collapses down to √(2 · ln(2) · 2^74) ≈ 1.177 × 2^37, or roughly 161 billion IDs per millisecond. Within that millisecond, the margin is vastly narrower. If you run thousands of parallel ingestion threads that don’t coordinate their sub-millisecond counter bits, you are operating much closer to the edge than most architectural diagrams admit.

The takeaway

UUIDv4 is fine. Use it without anxiety for local IDs, database keys, and distributed tracing.

Just stop telling junior engineers that collisions are “physically impossible.” They aren’t. Globally, they are an inevitability. Your architecture works because your data is isolated, your indexes are scoped, and your entropy sources are uncorrupted—not because 122 bits is an infinite god-mode cheat code.

When you design systems, design them knowing the boundaries of your abstractions. Because the moment you rely on “mathematical impossibility” as an architectural load-bearing pillar, scale has a funny way of catching up with you.