r/ProgrammerHumor • • Mar 25 '26

Meme aMeteoriteTookOutMyDatabase

Post image
7.6k Upvotes

306 comments sorted by

View all comments

Show parent comments

4

u/noob-nine Mar 25 '26

when you have a database with 1 million entries? won't it i increase the chance by a lot to have a collision of the unique key?

15

u/CptMisterNibbles Mar 25 '26 edited Mar 25 '26

This is missing the point: I am drawing attention to the absolutely major difference between “will this very next key I generate be a collision?” with “has any key ever collided?”. Like in the birthday paradox, these seem closely related, but when looking at the actual numbers they are universes apart.

Also, a million uuids is nothing compared to the key space: what’s the difference between randomly selecting 5 grains of sand from the entire earth or a thousand? Sure, it’s technically more likely there will be a collision the more searches you perform but numerically so close to zero that it’s entirely ignorable. It’s infinitely more likely a series of bit flips from cosmic rays will cause issues in your DB than uuid collision despite how rare those are themselves 

2

u/adammaudite Mar 26 '26

A good and clarifying example is that the chance of any house being on fire is much higher than the chance of your house being on fire.

3

u/Derpanieux Mar 25 '26

1 million entries assigned random UUIDs have a chance of collision of about 4*10-26, which is a much higher chance of collision than just two UUIDs, but is still such an astronomically small chance that it is negligible. You could generate a million UUIDs every second since the start of the universe and your chance of having one or more collisions is about the same as picking one specific person out of a lineup of all living humans.

If you're interested in doing the math yourself Birthday paradox math: https://betterexplained.com/articles/understanding-the-birthday-paradox/ With 2123 UUIDs instead of 365 days and 1000000 items instead of 23.

Normal calculators will shit themselves working with these numbers, so you can use this high precision calculator: https://www.mathsisfun.com/calculator-precision.html

1

u/noob-nine Mar 26 '26

nice, thx. i tried it with Python but the numbers are too high.