UUID vs Auto-Increment Integer Primary Keys
A comparison of UUIDs versus auto-increment integers as database primary keys.
Auto-Increment Integers
They are short, fast, and have good index locality. However, they make it hard to merge multiple databases, expose the total record count through their sequential numbering, and make it difficult for an application to generate IDs ahead of time or across distributed nodes.
UUID
In a distributed environment each node can generate them independently without collisions, and the values are hard to guess. On the other hand, at 128 bits they are larger than integers, and random v4 values are inserted scattered across the index, which can hurt write performance.
How to Choose
For an internal system on a single database, integers are simpler and more efficient. If you need a distributed system, a public API, or to merge data from multiple sources, UUIDs are a better fit—especially the time-ordered v7. A common compromise is to keep an internal integer PK alongside a UUID for external exposure.