UUID generator: unique identifiers for development
A UUID (Universally Unique Identifier) is a 128-bit identifier represented as 32 hexadecimal characters in 8-4-4-4-12 format. The probability of generating two identical UUIDs is so low it is considered practically impossible, making them ideal as primary keys and unique references.
Most used UUID versions
- UUID v4: fully random, the most popular for general use cases.
- UUID v1: based on timestamp and device MAC address.
- UUID v5: deterministic, generated with SHA-1 hash from namespace + name.
- UUID v7: new standard with sortable timestamp, ideal for databases.
When to use UUID vs. autoincrement
Auto-increment IDs are simple but reveal information (ID 1337 indicates at least 1337 records exist). UUIDs are opaque, do not reveal volume, allow creating records offline without server coordination, and facilitate merging distributed databases.
UUID in databases
UUID v4 has a disadvantage in relational databases: being random, they fragment B-tree indexes, degrading performance. UUID v7 (with sortable timestamp) solves this problem while maintaining uniqueness and improving insertion efficiency.