How Unique is a UUID? Should we use them instead of auto-incrementing?
We had a discussion today about the uniqueness of UUIDs (or GUID). In case you didn't know, according to Wikipedia, a UUID is:
"an identifier standard used in software construction, standardized by the Open Software Foundation (OSF) as part of the Distributed Computing Environment (DCE)."
The uniqueness of a UUID is 1 2^128. Now this doesn't really mean much to most people so the part I found particularly interesting is the uniqueness in terms we can try to understand. From Stackoverflow:
"consider the observable universe, which contains about 5×10^22 stars; every star could then have 6.8×10^15 universally unique GUIDs."
Wow.
Here's another way to write the probability:
1 in 340,000,000,000,000,000,000,000,000,000,000,000,000
or
"In other words, only after generating 1 billion UUIDs every second for the next 100 years, the probability of creating just one duplicate would be about 50%. The probability of one duplicate would be about 50% if every person on earth owns 600 million UUIDs."
Stop and think about that for a second.
This raises the question. Given the fact they basically are unique, should we use them for a primary key instead of auto-incrementing in a database? There are good reasons to use either as a primary key.
Which do you use and why?










