graphaware / neo4j-uuid

GraphAware Runtime Module that assigns a UUID to all nodes (and relationships) in the graph transparently
103 stars 22 forks source link

Question: uniqueness #36

Closed pito-svk closed 7 years ago

pito-svk commented 7 years ago

I am just curious if this extension can always guarantee uniqueness for uuid properties.

Thanks.

bachmanm commented 7 years ago

Yes, that's the point of a UUID

Joshfindit commented 7 years ago

Because I asked this question (of the DayOne author), and felt the need to push back when I got a similar answer, I offer this:

UUID v4 itself almost guarantees that the number generated will be unique:

"The odds of drawing the same UUID twice from this large a hat of possible UUIDs can be calculated using the probability theory for the birthday problem. About 100 trillion version 4 UUIDs would need to be generated to have a 1 in a billion chance of a single duplicate ("collision"). The chance of one collision rises to 50% only after [4.6 quintillion] have been generated, which is equivalent to 1 billion UUIDs generated per second for about 146 years."

If we're being extremely meticulous, this means that there is some chance that a duplicate will be generated.

This chance can be eliminated if we check whether a newly-generated UUID already exists, and simply regenerate if it does. That being said, the computational cost of doing this check 4.6 quintillion times starts to add up just to negate the chance that you find a single collision.

The only question left is does neo4j-uuid do a check?

bachmanm commented 7 years ago

It doesn't - we take the view that this low probability effectively equals 0

ikwattro commented 7 years ago

Note that, 99% of the use cases of using neo4j-uuid will imply a uniqueness constraint on the label/property pair, so even if we don't check it, we are backed by a TransactionFailure from Neo4j itself.