The Problem with UUID v4 in Databases

UUID v4 is everywhere. Nearly every database tutorial tells you to use it as a primary key. But there is a hidden performance cost: random UUIDs destroy your database indexes. When you insert a row with a UUID v4 primary key, your database has to slot it into a B-tree index at a random position. At millions of rows, the index becomes fragmented, reads slow down, and write performance tanks.

What is UUID v7?

UUID v7 is a new UUID standard (RFC 9562, published April 2024) that solves the ordering problem. It encodes a Unix millisecond timestamp in the first 48 bits, followed by random bits. UUID v7 values are monotonically increasing — UUIDs generated later are always lexicographically greater than earlier ones. Your database index stays ordered and compact.

UUID v1 vs v4 vs v7

VersionBasisSortableBest For
UUID v1MAC address + timeYes (partial)Legacy systems
UUID v4RandomNoSmall-scale distributed IDs
UUID v7Unix time ms + randomYesDatabase PKs, event IDs, logs

Real Performance Numbers

Benchmarks on PostgreSQL with 10 million rows: UUID v7 achieves ~120,000 inserts/sec vs ~45,000 for UUID v4, with 60% smaller index size. Shopify, GitHub, and Stripe all use time-ordered IDs for exactly this reason.

Generate UUIDs via API

Use the ToolCenter UUID API to generate v1, v4, or v7 UUIDs in bulk:

curl -X POST https://api.toolcenter.dev/v1/uuid 
  -H Authorization: Bearer YOUR_API_KEY 
  -H Content-Type: application/json 
  -d {version: 7, count: 5}

The API also supports parsing any UUID to extract version, variant, and the timestamp embedded in v7 UUIDs.

UUID v7 vs ULID

Both are time-ordered, but UUID v7 uses standard UUID format (backwards compatible with existing UUID columns), while ULID uses Base32 encoding and is not UUID-compatible. UUID v7 is the easier migration path for existing systems.

When NOT to Use UUID v7

Library Support

Summary

UUID v7 gives you the global uniqueness of UUIDs with the index performance of auto-increment integers. If you are building a new system or dealing with high-write database loads, UUID v7 is worth adopting. Try the ToolCenter UUID Generator API today.