Is it possible for an ASP.NET server to generate the same GUID to more than one user?

StackOverflow https://stackoverflow.com/questions/272169

  •  07-07-2019
  •  | 
  •  

Question

I have seen the GUID Collisons discussions but just wanted your thoughts on whether there could be a GUID collision if both clients accessed the same web page that generates the GUID at exactly the same time (- probably down to the micro-second) ?

Was it helpful?

Solution

It's theoretically possible, but highly unlikely.

OTHER TIPS

No. If that happens rush out and buy a lottery ticket!

On a single server, no, it isn't possible. Version 4 Guids are made up (amongst other things) of a pseudo-random 54-bit value, and as I understand those, they cycle through all values before repeating.

If creating on more than one server, then it is possible to have a guid clash, although that is highly highly unlikely.

Refer to RFC 4122, specifically section 4.1.5. Modern Windows uses v4 UUIDs, I believe.

From Wikipedia, the free encyclopedia

A Globally Unique Identifier or GUID (pronounced /ˈguːɪd/ or /ˈgwɪd/) is a special type of identifier used in software applications in order to provide a reference number which is unique in any context (hence, "Globally"), for example, in defining the internal reference for a type of access point in a software application, or for creating unique keys in a database. 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. For example, consider the observable universe, which contains about 5×1022 stars; every star could then have 6.8×1015 universally unique GUIDs.

If you generate lots and lots of GUIDs, then likelihood of collision is getting quite high due to Birthday paradox. Theoretically GUID collision should be highly unlikely (naïve intuition) but practically it happens from time to time.

Sure, it's waste of time to handle these collisions programatically but you should still write your code in a way that if it happens, then your code should fail loudly, not quietly and undetected.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top