Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any possibility that GUID will all be used up?

Tags:

sql

guid

uuid

math

Given that each GUID is represented by 16 bytes. So at best there are 2^128 possibilities = 3.4028237e+38 possible GUIDs.

Will it be possible that it will all be used up?

like image 453
Chris Yeung Avatar asked Apr 16 '15 17:04

Chris Yeung


People also ask

Can a GUID never be duplicated?

While each generated GUID is not guaranteed to be unique, the total number of unique keys (2128 or 3.4×1038) is so large that the probability of the same number being generated twice is very small.

How many possible GUIDs are there?

Question: How many GUID combinations are there? Answer: There are 122 random bits (128 – 2 for variant – 4 for version) so this calculates to 2^122 or 5,316,911,983,139,663,491,615,228,241,121,400,000 possible combinations.

What are the chances of two GUIDs being the same?

GUID generation algorithm 4 fills the GUID with 122 random bits. The odds of two GUIDs colliding are therefore one in 2¹²², which is a phenomenally small number. When you are dealing with rates this low, you have to adjust your frame of reference.

Is it safe to assume GUID is unique?

In general, yes it is safe to assume. If your GUID generator is truly random, the possibilities of a clash within a 1000 GUIDs is extraordinarily small.


2 Answers

To show you how big 2^128 GUIDs is:

1 GUID = 16 bytes.

Therefore 2^128 GUIDS would need 2^4 * 2^128 bytes to be stored.

2^4 * 2^128 = 2^132 bytes

Using Python, I calculated that this would take:
4,951,760,157,141,521,099,596,496,896 terabytes.

So first you would need to worry about being able to store that many GUIDs, before you could even consider running out of them.

Basically: it is impossible for you to run out.


Collisions

Just because I've heard people worry about collision so many times, I will expand my answer to include an analysis of the possibilities of collisions.

The average number of UUIDs you would need until you get a collision is:

2^128 / 2 = 2^127

This means that there is a 50% chance that by the time you generate 2^127 GUIDs, you will get a collision. The number of GUIDs you need for this is:

170141183460469231731687303715884105728 GUIDs

Someone please correct me if I'm wrong but: this means the potential for generating a collision is so small, it is not even worth checking if the UUID that was just generated already exists in your database.

Note: This is all assuming the UUIDs are generated with a good algorithm for Randomness and a good source of Entropy.

like image 90
John Avatar answered Sep 18 '22 06:09

John


No. Even if you assume extremely high usage of GUIDs in some area, and extremely long time scales, the key point about GUIDs is their uniqueness. As soon as you start to get repetitions with any probability that is of practical relevance, people will stop using GUIDs, and therefore won't use up any more of them. Sure, they might use some numbers which look like GUIDs in some areas, where sufficiently low usage can still help ensure local uniqueness, but those would only be LUIDs, and with a bit of luck people will also call them this way.

like image 28
MvG Avatar answered Sep 21 '22 06:09

MvG