When you need a unique identifier and do not want to ask the database for the next number every time, the UUID solves the problem. This guide explains what a UUID v4 is, how it is built, when to use it, and how it differs from an auto-increment ID.
1. The problem it solves
Imagine two servers creating records at the same time, without talking to each other. How do you guarantee their identifiers do not clash? The UUID lets you generate an identifier that is unique without central coordination: each side creates its own and, in practice, they never match.
2. What a UUID v4 is
A UUID (Universally Unique Identifier) is a 128-bit identifier. It is shown as 32 hexadecimal digits in five groups:
550e8400-e29b-41d4-a716-446655440000
Version 4 is the most used: it is almost completely random. Of its 128 bits, 122 are generated at random; the other 6 set the version and variant.
3. Anatomy
- 128 bits total.
- 4 bits indicate the version (the
4digit in the third group). - 2 bits indicate the variant.
- 122 bits left: random.
That means nothing about your machine or the time is encoded inside: a UUID v4 does not reveal when or where it was created.
4. When to use it
- Primary keys in distributed databases.
- Request IDs to trace a request in your logs.
- File names that are unique without querying anything.
- Reference tokens that are not secret.
5. Why they almost never collide
With 122 random bits, the space of possibilities is so huge that the probability of generating two equal ones is negligible. You would have to produce billions per second for years for a collision to be even likely.
6. UUID vs auto-increment ID
| UUID v4 | Auto-increment ID | |
|---|---|---|
| Generation | On the client, no DB | The DB assigns the next |
| Coordination | Not needed | Needed |
| Leaks count | No | Yes (reveals volume) |
| Size | 128 bits | 32–64 bits |
| Order | Not ordered | Ordered |
Generate a UUID v4 instantly — created with your browser’s cryptographic generator, 100% local, nothing is uploaded → open the UUID generator
7. Privacy: generated in your browser
A good generator uses the browser’s cryptographic API (crypto.getRandomValues), which produces quality randomness. Because it is generated locally, the identifier never leaves your device.
If you work with data integrity as well as identifiers, you may want to read what is SHA-256.
8. Summary
A UUID v4 is a 128-bit identifier, almost entirely random, that you can generate without central coordination and that in practice never collides. It is ideal for distributed keys, request IDs and file names, at the cost of more space than an auto-increment and no ordering. To get one instantly and locally, use the generator.