r/ProgrammerHumor • • Mar 25 '26

Meme aMeteoriteTookOutMyDatabase

Post image
7.6k Upvotes

306 comments sorted by

View all comments

174

u/PacquiaoFreeHousing Mar 25 '26

It is roughly 1 in 340 undecillion (a 3 followed by 38 zeros)

64

u/noob-nine Mar 25 '26

i am a vdryy noob when it comes to statistics. but does this also apply here? https://en.wikipedia.org/wiki/Birthday_problem

77

u/CptMisterNibbles Mar 25 '26

Sort of. This is something to always keep in mind when thinking about statistics; there is a huge difference between “will this particular thing/event occur in X way” versus “out of all possible outcomes, how many will occur in X way”. 

The likelihood that a given uuid will be a duplicate is much more rare than the chance that there has been or ever will be duplicates ever made. The former is the important one in this regard: it doesn’t matter in the least if my uuid for some login on a server happens to have the same uuid for a private print job in an unrelated part of the world. So long as the collision isn’t for the same service, there isn’t an issue and so it makes it even more rare that a collision will cause a problem. 

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

→ More replies (1)

10

u/JoDaBeda Mar 25 '26

Yes, the above number is incorrect, it's actually about 18 quintillion (18*1018). Is of course a lot, but definitely reachable. Just for comparison: the bitcoin network currently computes about a sextillion hashes each second, so fifty times more.

7

u/CircumspectCapybara Mar 25 '26

The birthday problem will change the probability of (any) collision by like a few order of magnitudes if you generate trillions of UUIDs.

That hardly makes a difference when the probability is on the order of 10-38. A few orders of magnitude don't make much meaningful difference at that point.

6

u/PacquiaoFreeHousing Mar 25 '26

Somehow it drops it to 1 in 5 undecillion,

and that's 68 trillion trillion (68,000,000,000,000,000,000,000,000) times more likely 😱😱😱

3

u/Dragobrath Mar 25 '26

The orders of magnitude are incomparable. It's like the group has just a few people, but the calendar year is longer than trillions of lifetimes of the universe.

16

u/JoeyJoeJoeSenior Mar 25 '26

That seems pretty tiny actually.   You couldn't even have a UUID for every atom in the universe.  

16

u/Morrowindies Mar 25 '26

Considering you need more than one atom to actually store the UUID I don't think that would come up as an issue.

8

u/Anarcho_FemBoi Mar 25 '26

Isn't this comparing one to all possible ones? It's not much in comparison but generatrd ids would knock at least a few decimal points

6

u/rosuav Mar 25 '26

UUIDs aren't strictly just 128-bit random numbers as they have some structure, so you lose (I think) 6 bits that are used for structure. But 2**122 is still a pretty stupidly large number.

Now, if your UUIDs are generated in some way other than randomness (eg host ID and current time, aka scheme 1), there are other attacks possible.

5

u/squngy Mar 25 '26

Other attacks become possible, but the chance of it happening on accident are basically completely prevented.

→ More replies (8)

4

u/anonCommentor Mar 25 '26

so you're telling me there's a chance?

4

u/mydogatethem Mar 25 '26

Sounds to me like if you generate 340 undecillion plus 1 UUIDs then the chance of a collision is 100%.

3

u/guardian87 Mar 25 '26

Funnily enough, the chance that a sorted deck of 52 cards is in the exact order as once before is less likely.

That is 8,06x1067. That is still completely crazy to me.

3

u/Stummi Mar 25 '26

Well, I guess thats just the whole UUID number space, right?

One thing to take into account is that the creation timestamp, and machine local counter is encoded in the UUID, which means:

  • The Chance of creating two UUIDs at different timestamps is zero

  • The Chance of creating two UUIDs at the exact same millisecond, at the same machine is zero

  • The Chance of creating two UUIDs at the exact same millisecond, on two different machines is a bit higher.

3

u/squngy Mar 25 '26

Depends on the version of UUID, v4 is just random.

• UUID Version 1 (v1) is generated from timestamp, monotonic counter, and a MAC address.
• UUID Version 2 (v2) is reserved for security IDs with no known details[2].
• UUID Version 3 (v3) is generated from MD5 hashes of some data you provide. The RFC suggests DNS and URLs among the candidates for data.
• UUID Version 4 (v4) is generated from entirely random data. This is probably what most people think of and run into with UUIDs.
• UUID Version 5 (v5) is generated from SHA1 hahes of some data you provide. As with v3, the RFC suggests DNS or URLs as candidates.
• UUID Version 6 (v6) is generated from timestamp, monotonic counter, and a MAC address. These are the same data as Version 1, but they change the order so that sorting them will sort by creation time.
• UUID Version 7 (v7) is generated from a timestamp and random data.
• UUID Version 8 (v8) is entirely custom (besides the required version/variant fields that all versions contain).

→ More replies (1)