Lurker News
I know what you're thinking... and I still can't believe it, but...

This morning, our database flagged a duplicate UUID (v4). I checked, thinking it may have been a double-insert bug or something, but no.
The original UUID was from a record added in 2025 (about a year ago), and today the system inserted a new document with a fresh UUIDv4 and it came up with the exact same one:
b6133fd6-70fe-4fe3-bed6-8ca8fc9386cd
We're using this: https://www.npmjs.com/package/uuid
I thought this is technically impossible, and it will never happen, and since we're not modifying the UUIDs in any way, I really wonder how that.... is possible!? We're literally only calling:
import { v4 as uuidv4 } from "uuid";
const document_id = uuidv4();
... and then insert into the database, that's it.
Additionally, the database only has about 15.000 records, and now one collision. Statistically... impossible.
Has that ever happened to anyone?! What in the...

Comments (347) 79 threads

Earlier comments
adyavanapalli5 replies#
What you're talking about is so extremely rare that it's much more likely that the entire Earth is destroyed by an asteroid right this inst...
delichon2 replies#
About as rare as an asteroid typing an ellipsis and clicking the add comment button.
throw0101c#
Well, this joke dates back to (at least) the dial-up days where {#`%${%&`+'${`%& NO CARRIER
xerox13ster#
That’s just a result of jounce from localized gravity effects and atmospheric pressure disturbances in the moments before impact.

Think the ultrasonic typing hacking scene in Pantheon combined with the keyboard bouncing due to rumbling.

sebazzz#
Well it would be statistically even rarer for that UUID collision to happen and the earth to be destroyed by an asteroid.
crazylogger1 reply#
For a single database using UUIDs, yes, it's astronomically rare. But it's quite a different thing to say that no computer system on Earth has ever experienced a UUID collision. The number of systems out there is also astronomical.
nathanmills1 reply#
>The number of systems out there is also astronomical.

Not even close

moi2388#
Sure it does. Planets are astronomical, and we only have 8 of those in our solar system.
thomasmg#
It is not quite as rare. I calculated it to be less common than being hit by a meteorite, and added a section about that and the Birthday Paradox to Wikipedia, to the article about UUIDs. It got removed / replaced a few years ago however. (If my source was correct, there was actually a woman hit by a meteorite, but she survived, with a leg injury.)

If you do have a UUID collision, chances are extremely high that it's either a software bug, or glitch in the computer. It could be a cosmic ray. Cosmic rays messing with the computer memory or CPU are actually relatively common.

spindump8930#
It's very common if you improperly seed, as others in the thread brought up! Or in your framing, as rare as earth getting hit if it were surrounded by a sci-fi density asteroid field.
juancn1 reply#
Something off on how the RNG is initialized? Lack of entropy?

If the rng is not customized it will use:

    const rnds8 = new Uint8Array(16);
    export default function rng() {
        return crypto.getRandomValues(rnds8);
    }
getRandomValues doesn't specify a minimum amount of entropy.
Hizonner1 reply#
It's a near certainty that something is badly wrong with the RNG, and, yes, probably in how it's seeded.

It's probably messing up the cryptography, too.

Onavo#
But defaults should be sane and safe. RNG isn't the sort of thing you want to be messing up. Every JS dev was taught that Math.random is not safe by default, but the crypto package is.
Geee4 replies#
According to the many-worlds interpretation of quantum mechanics, there's bound to be one branch of universe where every UUID is the same. Can you imagine what those guys are thinking?
nyantaro1#
This is why I am not a fan of the Everett approach
zeeveener#
"Huh, this is just an identity function. Cool. Let's move on."
BobaFloutist1 reply#
Not only that, there's vastly more where every UUID except one is the same, but they never got to that one because they didn't ever use them.

Or where the first two are unique, but every following one is one of the first two.

beng-nl#
One where all uuids are always different whenever the person who wrote the implementation tries it, regardless of computer. And whenever it’s someone else, always the same.
suprjami#
They probably just generate "the UUID" then add an increasing number on the end so it's unique. Problem solved.
D2OQZG8l5BI1S063 replies#
That makes sense. I'm not sure why anybody would generate UUIDs in browsers though, it seems to defeat the purpose.
danpalmer#
Tell that to Segment. Hopefully they've fixed that, but they didn't seem to think it was a problem years ago (spoiler: it was a big problem).
perlgeek#
When you do CQRS, you basically have to generate some form of unique identifier in the client. Why not a UUID in the browser?
dylanhouli#
> I'm not sure why anybody would generate UUIDs in browsers though, it seems to defeat the purpose.

How about for offline-first apps?

Load more comments