Why use apps to generate custom uuid instead of database id?

Why should I use an app to generate UUID instead of using the database id? is there an advantage?

I see a lot of apps that generate UUID blocking. so how is it possible in a database id like mysql or mongodb?

+2


source to share


1 answer


One of the theoretical reasons for using random UUIDs rather than relying on database IDs is the ability to do concurrent inserts of new records without blocking and incrementing the counter, or even looking up a unique index.

If you have an auto-incrementing field, something must support this counter. The only way to ensure that the auto-increment facility will work correctly is to lock this counter as it increases, or do something else with transaction-y. If you have a random ID, you don't have to.



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 it’s better to just drop it and use random IDs.

But these reasons are very rarely applied in practice. You will need huge amounts of INSERT traffic to achieve the payoff. I think the use of most UUIDs is not out of necessity, but because of the "coolness" or ignorance of what they are really intended for.

+2


source







All Articles