Question

why should I use an app to generate UUID instead using database id's? is there an advantage?

I see many apps that generates UUID preventing colision. so than is this possible to happen in database id like mysql or mongodb?

Was it helpful?

Solution

One theoretical reason for using random UUIDs instead of relying on database IDs is the ability to do parallel inserts of new records without locking and incrementing a counter, or even looking up a unique index.

If you have an auto-increment field, something needs to maintain this counter. The only way you can guarantee that the auto-increment facility will work correctly is by locking this counter while incrementing it, or doing something else transaction-y with it. If you have a random ID, you don't have to do it.

Another reason is the ability to perform parallel distributed inserts in a master-master environment. When different database servers access the same data, it would be even more expensive to maintain a shared counter between the two servers, so better to just give it up from the start and use random identifiers.

But these reasons are very rarely applicable in practice. You would need huge volumes of INSERT traffic to reach payoff. I guess most UUID usage is not because of necessity but because of "coolness" or ignorance towards what they really are for.

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