What is a UUID?
Short answer
A UUID (Universally Unique Identifier) is a 128-bit value used as an identifier that does not need a central server to stay unique. The most common form, UUID v4, is almost entirely random, so two generated values practically never collide.
What a UUID looks like
A UUID is written as 32 hexadecimal digits in five groups separated by hyphens, in the pattern 8-4-4-12.
f47ac10b-58cc-4372-a567-0e02b2c3d479Why it stays unique
UUID v4 fills almost all of its 128 bits with random data (122 bits after the version and variant markers). The space is so large that generating values randomly will, in practice, never produce a duplicate, even across many independent machines that never talk to each other.
When to use a UUID
- Identifiers you must create on the client before talking to a server
- Keys that must be unique across multiple databases or services
- Public ids where a guessable, sequential number would leak information
When not to use one
Random UUIDs are larger than integers and do not sort by creation order, which can hurt database index performance. If you need ordered keys, consider UUID v7 or a database sequence instead.