Developer Tools

UUID v4 vs v7: Which Should You Use for IDs and Database Keys?

UUIDs let systems create IDs anywhere without asking a central server. The newer version 7 fixes a real performance problem with the classic random v4.

In this article
  1. What a UUID is
  2. Version 4: random
  3. Version 7: time-ordered
  4. Which one to choose
  5. How to generate UUIDs
  6. Storage tips
  7. UUIDs are not secrets

What a UUID is

A UUID (universally unique identifier) – called a GUID in Microsoft systems – is a 128-bit number written as 32 hexadecimal characters in five groups: 3f2b8c1e-9a4d-4e7b-8c21-5d6f7a8b9c0d. Any computer can generate one independently, and the chance of two random UUIDs ever being the same is so small that it can be ignored in practice. That makes them ideal when IDs are created in many places: different servers, phones working offline, or several services writing to the same database.

UUID GeneratorGenerate random UUID v4 or time-ordered UUID v7 identifiers, one or up to 1,000 at a time. Upper or lower case, with or without hyphens or braces.
Open the free tool

Version 4: random

A v4 UUID is 122 bits of randomness plus a few fixed bits that mark the version. It reveals nothing about when or where it was created, which is good for privacy. Its weakness is order: new v4 IDs are scattered randomly. In databases that store rows in key order (such as the B-tree indexes used by PostgreSQL and MySQL’s InnoDB), inserting random keys means writing all over the index, which can slow down large tables.

Version 7: time-ordered

Standardised in RFC 9562 (2024), a v7 UUID starts with the current Unix time in milliseconds, followed by random bits. New IDs therefore sort after older ones, so database inserts land at the end of the index – much like auto-increment numbers – while still being unique across machines. You can even read the creation time from the first 12 hex digits.

Which one to choose

UseChoose
Primary keys in a databasev7
Events, logs, messages you will sort by timev7
Public IDs where creation time should stay hiddenv4
Test data, file names, random tokens in non-security rolesv4 or v7

How to generate UUIDs

  1. Open the UUID Generator.
  2. Choose v4 or v7.
  3. Set how many – up to 1,000 at once – and the format: lowercase with hyphens (standard), uppercase, without hyphens or in {braces}.
  4. Copy or download the list.

Generated v7 IDs are guaranteed to sort in creation order even when many are made within the same millisecond.

Storage tips

  • Use a native UUID column type where available (PostgreSQL uuid) – 16 bytes instead of 36 characters.
  • Stick to one text format across systems; “ABC…” and “abc…” may not match in string comparisons.
  • Keep auto-increment numbers if you have a single database and do not expose IDs publicly – they are smaller and simpler.

UUIDs are not secrets

A UUID identifies something; it does not protect it. Do not use UUIDs as passwords, API secrets or password-reset tokens on their own. For secrets, use the Password Generator or your framework’s secure token functions. To turn a v7 timestamp into a date, paste the milliseconds into the Timestamp Converter.

UUID GeneratorGenerate random UUID v4 or time-ordered UUID v7 identifiers, one or up to 1,000 at a time. Upper or lower case, with or without hyphens or braces.
Open the free tool
Keep reading

Related articles

All articles
Dev

How Strong Should Your Password Be? Length, Symbols and Entropy Explained

Rules like “one capital, one number, one symbol” produce passwords that are hard to remember and easy to crack. Here is what actually makes a password strong.

3 min read
Dev

How to Verify a Download with a SHA-256 Checksum

Software sites often list a long “SHA-256” code next to a download. Comparing it with your file takes a minute and proves the file is exactly what the publisher released.

3 min read
Dev

Unix Timestamps Explained – Seconds, Milliseconds and Time Zones

Numbers like 1767225600 appear in logs, APIs and databases. They are simply a count of seconds – once you know the rules, converting them is easy.

3 min read