A UUID is a 128-bit identifier you can generate anywhere without coordination. That property makes it attractive as a primary key, and v4 — the familiar random one — quietly makes your database slower in a way that only shows up at scale.
Why random keys hurt
Database indexes are ordered structures. Sequential keys append to the end, touching the same pages repeatedly, which stay cached. Random keys land in arbitrary positions, so each insert may touch a different page and the working set becomes the entire index.
On a small table this is invisible. On a large one it shows up as steadily degrading insert performance and a cache that no longer helps, because there is no locality left to exploit.
What v7 changes
UUIDv7 puts a 48-bit millisecond timestamp in the leading bits and fills the rest with randomness. The result is still a UUID — same length, same format, still generated without coordination — but values created around the same time sort near each other.
That restores the locality sequential keys had, while keeping the ability to generate identifiers on any machine. For most new tables it is simply the better default.
When v4 is still right
v7 encodes creation time to the millisecond, and anyone holding the identifier can read it. If the identifier is public — in a URL, an API response, a filename — that may leak more than you want: when an account was created, or how quickly records are being added.
For public-facing identifiers where that matters, v4 remains the right choice. A reasonable pattern is v7 internally as the primary key and a separate v4 exposed externally.
In short
Use v7 for database keys and v4 for anything public. Both are collision-safe in practice; the difference is index locality against information leakage.
UUID Generator
Generate random v4 or time-ordered v7 UUIDs in bulk, in whichever format your system expects.
Keep reading
What makes a password strong (it isn't the symbols)
Why length beats complexity, what entropy in bits actually measures, and why the old advice about special characters made passwords worse.
MD5, SHA-1, SHA-256: which hash should you actually use?
What it means for a hash to be broken, why fast hashes are the wrong tool for passwords, and how to verify a downloaded file properly.
Base64 explained: what it's for, and what it is not
Base64 is an encoding, not encryption. What it actually solves, why it makes data a third larger, and when embedding a data URI is a mistake.