What Is a UUID and When Should You Use One?
What a UUID actually contains, why version 4 is random, and the trade-offs of using UUIDs as database keys.
A UUID is a 128-bit identifier designed to be unique without coordination. Version 4 UUIDs are random, which makes them safe to generate on any device without a central service.
Generate one or a batch, optionally uppercase, and copy the list into your database seed, test fixture or configuration file.
Runs locally in your browser — nothing is uploaded.
Version 4 UUIDs contain 122 random bits. The chance of a collision is negligible for practically any use case, though it is never exactly zero.
Other versions derive parts of the identifier from a timestamp, MAC address or name hash. Version 4 is purely random, which avoids leaking machine information.
Yes, but random UUIDs are not ordered, which can hurt index locality. Many systems use UUIDv7 for time-ordered identifiers instead.
UUIDv4 is random, which is good for unpredictability and bad for database index locality: random inserts scatter across the B-tree. For high-volume tables, UUIDv7 (time-ordered) gives uniqueness with better write performance.
Do not treat a UUID as a secret. It is an identifier; knowing one should not grant access. Authorisation belongs in the application layer, not in the identifier format.