What is a UUID — and why the id in your database looks like gibberish

You built your first app. Orders have ids 1, 2, 3. Logical, readable, you like it.
Then someone opens their order at /orders/57, changes the number to 56 out of curiosity — and sees somebody else's order. Or your first user writes in: "so you only have 8 customers?" They just looked at the number.
That's exactly why databases are full of gibberish like 550e8400-e29b-41d4-a716-446655440000. It's a UUID, and it wasn't invented for looks.
What a UUID is
A UUID (universally unique identifier) is a long id — 32 characters split by dashes into five groups. Its job: to be unique without asking anyone's permission.
Here's the trick. A regular 1, 2, 3 is handed out by the database: to learn its id, a row has to reach the database first. A UUID can be generated anywhere, any time — in the browser, in a mobile app on a plane, on three servers at once — and they won't collide.
You feel the difference the moment your app has to work offline. Someone writes a note on the subway — it already has an id, it can be linked to a photo and a list. Connection comes back, everything uploads as-is. With an auto-number you'd be waiting for the network.
Where the uniqueness comes from
The common flavour is UUIDv4: 122 random bits. No magic — just an enormous number of possibilities.
A collision is theoretically possible and practically not. For the odds to become meaningful you'd need to generate billions of ids. Your app will never get near those numbers.
Which leads to something important: a UUID is not security. It's unique, not secret. If a user can open someone else's order just by knowing the id, the problem isn't the number — it's the missing permission check. A UUID only removes the ability to walk through everything by bumping a digit in the URL.
The quiet problem with v4 — and what v7 fixes
Now for the part worth reading for.
To find rows fast, a database keeps an index — a sorted structure. When ids grow in order (1, 2, 3), each new row lands at the end: the database keeps writing to the same "hot" spot.
UUIDv4 is random. Every new row flies into an arbitrary point in the index. The database has to shuffle neighbours around and split pages. On a small project you won't notice; on a large table, inserts slow down noticeably.
In 2024 the RFC 9562 standard arrived with UUIDv7. The idea is simple: the first 48 bits are the creation time in milliseconds, the rest is random. You get an id that's still unique but grows over time — so it lands at the end of the index again, like a plain number.
Nice side effect: rows sorted by UUIDv7 come out in creation order. A separate "created at" column for sorting stops being mandatory.
The honest downside: a UUIDv7 reveals when the row was created. Usually harmless — but if "this account was created July 3 at 14:22" is itself sensitive, use v4.
Which one you should take
- A plain number (1, 2, 3) — for internal tables nobody outside ever sees. Simple, and easy to debug.
- UUIDv7 — a sensible default for anything that shows up in URLs or arrives from clients.
- UUIDv4 — when the id must reveal absolutely nothing, including time.
One practical rule: don't mix them. One table, one kind of id. Moving a live project from auto-numbers to UUIDs means a migration that changes a column type and every relation pointing at it — tedious and risky. Deciding up front is cheaper.
Also check whether your database can generate UUIDs itself — in most, it's one built-in function and you don't need to build anything.
Is it OK to show a UUID in the URL?
Yes — that's usually the point. Just remember it isn't a password. Links get forwarded and settle into browser history and logs, so check access on the server rather than treating "knows the link" as permission.
Will UUIDs slow my database down?
On a typical project you won't notice. A UUID takes more space than an integer, and v4 is harder on the index — but that starts to matter at millions of rows. If it worries you, use v7 and stop thinking about it.
How is a UUID different from a hash?
A hash is computed from content: same text, same hash. A UUID is computed from nothing — it's just a unique label. There's a separate piece on the first one: what hashing is. And to query a table with any kind of id, see what SQL is.
The AI Architect 2027 course: step by step from computer basics to your own app and first customers. 543 short lessons on your phone.





