All posts

UUID v4 vs v7: Which Should You Use in 2026?

A practical comparison of UUID v4 and v7 — when to use each, performance implications, and database indexing considerations.

UUIDs Are Everywhere

Universally Unique Identifiers (UUIDs) are 128-bit values used to identify resources without a central authority. They look like this:

550e8400-e29b-41d4-a716-446655440000

If you've built a web app, you've used UUIDs — for user IDs, session tokens, API keys, database primary keys, or trace IDs.

UUID v4: The Random Standard

UUID v4 is the most widely used version. It's 122 bits of random data plus 6 bits of version/variant info.

Pros:

  • Truly random — no information leakage
  • Supported everywhere
  • Simple to generate

Cons:

  • Not sortable by time
  • Poor database index performance (random insertion)
  • No embedded timestamp

UUID v7: The New Default

UUID v7 (RFC 9562, finalized 2024) embeds a Unix timestamp in the first 48 bits, followed by random data.

Pros:

  • Time-sortable — newer IDs sort after older ones
  • Excellent database index performance (sequential insertion)
  • Embedded timestamp for debugging
  • Still unique enough for distributed systems

Cons:

  • Leaks creation time (privacy consideration)
  • Newer — not all libraries support it yet

When to Use Each

Use CaseRecommendation
Database primary keysUUID v7 (better index performance)
Session tokensUUID v4 (no timestamp leakage)
API keysUUID v4 (no information leakage)
Distributed trace IDsUUID v7 (time-sortable for debugging)
File namesUUID v4 (unpredictable)
Event/log IDsUUID v7 (time-ordered)

The Database Performance Difference

With UUID v4, new records insert at random positions in the B-tree index. This causes page splits and fragmentation — especially painful at scale.

With UUID v7, new records always insert at the end of the index (like auto-increment). This means sequential writes, no page splits, and much better write performance.

Benchmarks show UUID v7 primary keys can be 2-3x faster for write-heavy workloads compared to UUID v4.

Generate UUIDs Now

Need UUIDs quickly? Use our [free UUID generator](/tools/uuid-generator). Generate up to 100 at a time in standard, uppercase, or no-dash format.

UUIDs in Error Tracking

Every error event in Bugsly gets a UUID v7 event ID — time-sortable so you can correlate events chronologically across services. When you're debugging a distributed system and need to trace an error across microservices, time-ordered IDs make the timeline obvious. [Start tracking](/signup).

Try Bugsly Free

AI-powered error tracking that explains your bugs. Set up in 2 minutes, free forever for small projects.

Get Started Free