India · Dubai · Delivering worldwide+91 86603 71224info@pyalm.com
Pyalm Labs logo
Free Tools

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

How UUIDs work, why random v4 IDs hurt database performance at scale, and why time-ordered UUID v7 is now the recommended choice for primary keys.

Editorial disclosure: Pyalm publishes and maintains the products and free tools discussed on this site. Regulatory statements are linked to primary sources where applicable. No independent professional review is claimed unless a reviewer is explicitly named.

A UUID (universally unique identifier) is a 128-bit ID like 0192f1c4-8e5a-7b3d-9c41-6a2f0e8d1b57. It can be generated anywhere — a phone with no signal, a browser, any server — without asking a central database for the next number, and the chance of two ever colliding is negligible.

Why use UUIDs at all?

  • Offline and distributed systems. Apps that create records offline (POS terminals, field apps) need IDs before they sync.
  • No guessable IDs. /invoice/1043 invites someone to try /invoice/1044; a UUID doesn't. (You still need proper access checks.)
  • Merging data. Records from several databases or tenants never clash.

The anatomy of a UUID

32 hex digits in five groups (8-4-4-4-12). The first digit of the third group is the version; the first digit of the fourth group encodes the variant. Paste any UUID into the free UUID Generator to see both.

Version 4: fully random

122 random bits. Simple, universal, supported everywhere (crypto.randomUUID() in every modern browser). The downside appears in databases: random IDs are inserted all over a B-tree index instead of at the end, causing page splits, poor cache use and bloated indexes on large tables.

Version 7: time-ordered

Standardised in RFC 9562 (2024), v7 puts a 48-bit Unix millisecond timestamp first, followed by random bits:

Property v4 v7
Unique without coordination ✓ ✓
Sorts by creation time ✗ ✓
Index-friendly inserts ✗ ✓
Reveals creation time No Yes (to the millisecond)

New v7 IDs always sort after older ones, so inserts land at the end of the index like an auto-increment column — while keeping all the benefits of UUIDs.

Which should you choose?

  • Primary keys and event IDs: UUID v7.
  • Tokens, file names, anything where revealing creation time matters: v4 — or better, a dedicated random token.
  • Never use UUIDs as secrets (password-reset or API tokens). Use the Password Generator style of high-entropy random strings instead.

Generating UUIDs

The free UUID Generator creates v4 or v7 IDs in bulk (up to 1,000), with uppercase, no-hyphen and brace options, using your browser's cryptographically secure random generator. It also validates UUIDs and reads the timestamp out of v7 (and v1) IDs.

Storage tips

  • Store UUIDs in a native uuid column (PostgreSQL) or BINARY(16) (MySQL), not as 36-character text.
  • PostgreSQL 18 includes uuidv7() natively; older versions can generate v7 in the application.
  • Keep the canonical lowercase hyphenated form in APIs.

How we use them

Pyalm's offline-first apps — like the Pyalm Books Android app and our POS — generate time-ordered IDs on the device so records can be created offline and synced later without conflicts. If you need an app that keeps working without a connection, see our mobile app development and custom software services.

UUID Generator | Hash Generator | Password Generator | Fake Data Generator | All free tools

Keep reading

More from Pyalm

Nov 27, 2026

Prescription Abbreviations: What OD, BD, TDS, SOS and 1-0-1 Mean

A plain-English list of prescription abbreviations: dose timing (OD, BD, TDS, QID), when to take (AC, PC, HS, SOS), routes, forms, the 1-0-1 dose grid and abbreviations to avoid.

Nov 27, 2026

Handwritten vs Typed Prescriptions: Which Is Safer?

Why legibility matters in prescribing, what changes when clinics move from handwritten to typed or electronic prescriptions, and how to keep a handwritten signature.

Nov 27, 2026

How to Write a Prescription in India: Format and Rules

A practical prescription format for doctors in India: required details, generic names in capitals, the 1-0-1 grid, Schedule H and controlled drugs, and keeping records.

Nov 27, 2026

Prescription Pad Design: Letterhead Template for Clinics

What a professional prescription letterhead should include, paper size, layout, bilingual Arabic and English pads, QR codes for verification and printing tips.

Nov 27, 2026

Prescription Errors: 10 Common Mistakes and How Clinics Prevent Them

The ten prescription mistakes that cause dispensing errors, from illegible names and decimal points to missing durations, and simple fixes for clinics.

Oct 16, 2026

How to Format and Validate JSON (and Fix the 6 Most Common Errors)

Why JSON breaks, how to read a validator's error message, and a quick routine for pretty-printing, minifying and fixing JSON from APIs, logs and config files.

Try the free UUID Generator

We use UUID v7 keys in Pyalm's own offline-first apps, like Pyalm Books on Android. Need an app that syncs reliably? That's what we build.

Open UUID Generator See custom software All free tools