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
AndreyK19841 reply#
Why not to have timestamp-uuid instead ?
dgellow2 replies#
How confident are you that your machines clocks are in perfect sync? What about the risk of clock drift + correction, or hardware issues?
croon#
Not GP, but: not confident. How confident would I be to avoid a (slightly lower entropy) UUID collision while also avoiding a clock desync landing on the exact same logged millisecond? Very, which is how confident I was about not encountering an UUID collision before this thread, so very++ I guess.
kdps1 reply#
I get why sync of mutiple machines matters for ordering and causality, but why is it a problem for uniqueness?
dgellow#
I just read UUIDv7, something I wasn't familiar with until now. That does address everything I had in mind yes. I assumed timestamp-uuid meant purely based on the timestamp precision, in which case you can get conflicts if you don't have a reliable clock across your system.

But UUIDv7 looks pretty awesome:
> What is a Version 7 UUID made from?
> unix_ts_ms: 019e0c7bfe93
> ver: 7
> rand_a: 0b6
> var: b
> rand_b: 55a99e023294673
So please ignore my previous comment :)

swah#
const blacklisted = ['b6133fd6-70fe-4fe3-bed6-8ca8fc9386cd'];
darqis#
pg 18 supports uuidv7 natively and your default should be unique and uuid7()

Load more comments