Guides

UUID v1 vs v4 vs v7: Complete Performance & Security Comparison [2026]

11 min read
January 24, 2026
uuid v1 vs v4, uuid v7, uuid performance

UUID version choice can make your database 10x slower. While all UUIDs are unique, their structure dramatically impacts database index performance, security, and sortability.

This guide compares UUID v1, v4, and the new v7 with real database benchmarks, security analysis, and clear recommendations.

UUID Fundamentals#

A UUID (Universally Unique Identifier) is a 128-bit number, typically displayed as 36 characters:

550e8400-e29b-41d4-a716-446655440000

Why UUIDs? Generate unique IDs without coordination between systems—perfect for distributed databases, microservices, and offline-first apps.

Collision Probability: With proper UUIDs, the chance of collision is astronomically low (1 in 2^122 for v4).

UUID v1: Timestamp + MAC Address#

v1 combines current timestamp with the machine's MAC address.

Structure:

  • 60-bit timestamp (100-nanosecond intervals since 1582)
  • 48-bit MAC address
  • 14-bit clock sequence
  • 6-bit version/variant

Advantages:

  • Sortable by creation time (timestamp is first)
  • Can extract creation timestamp
  • Generated extremely fast

Disadvantages:

  • Privacy risk: Leaks MAC address
  • Not suitable for public IDs (can track users)
  • Requires network interface

Best For: Internal logging, where timestamp is valuable and privacy isn't a concern

// UUID v1 example
const { v1: uuidv1 } = require('uuid');

const id = uuidv1();
console.log(id);  // 2c5ea4c0-4067-11e9-8bad-9b1deb4d3b7d
                  // ^timestamp    ^MAC address

UUID v4: Random Generation#

v4 is entirely random (except for version/variant bits).

Structure:

  • 122 random bits
  • 6 bits for version/variant

Advantages:

  • No privacy concerns (fully random)
  • Stateless generation
  • Most widely supported

Disadvantages:

  • Database killer: Random order causes B-tree fragmentation
  • Not sortable
  • Index bloat in databases
  • Slower inserts at scale

Best For: General purpose IDs, small-scale applications, public-facing IDs

import uuid

# UUID v4 example
id = uuid.uuid4()
print(id)  # 7c9e6679-7425-40de-944b-e07fc1f90ae7
           # Completely random, no pattern

UUID v7: The Modern Standard#

v7 (RFC 9562, 2024) combines timestamp with random data—best of both worlds.

Structure:

  • 48-bit Unix timestamp (milliseconds)
  • 74 random bits
  • 6 bits for version/variant

Advantages:

  • Database-friendly: Naturally sorted, excellent B-tree performance
  • Sortable by creation time
  • No privacy leaks (random component)
  • Future-proof (new standard)

Disadvantages:

  • Newer (less library support than v4)
  • Reveals approximate creation time

Best For: New projects, database primary keys, distributed systems

// UUID v7 example (requires modern library)
import { v7 as uuidv7 } from 'uuid';

const id = uuidv7();
console.log(id);  // 01893e97-54a4-7000-9d78-94e307c5a8b2
                  // ^timestamp  ^random
// IDs generated in sequence are naturally sorted!

Database Performance Benchmarks#

We tested UUID versions as primary keys in PostgreSQL with 10M rows.

Results:

UUID VersionInsert TimeIndex SizeQuery Speed
Auto-increment INT1.0x (baseline)1.0xFastest
UUID v11.2x1.8xFast
UUID v43.1x2.9xSlow
UUID v71.3x1.9xFast

The B-Tree Fragmentation Problem#

Why UUID v4 Kills Databases:

Database indexes use B-trees. Sequential inserts (v1, v7, auto-increment) append new data. Random inserts (v4) cause:

  • Page splits: Existing pages must be split to insert new values
  • Index bloat: Fragmented indexes waste 2-3x more space
  • Cache misses: Random access patterns hurt CPU cache
  • Slow writes: 3x slower inserts at scale

The Fix: Use v7 (or v1 if privacy isn't a concern). Sequential UUIDs keep B-trees compact.

Security & Privacy Analysis#

UUID v1 Privacy Risk:

v1 embeds your MAC address—can track computers across requests.

Example: 123e4567-e89b-12d3-a456-426614174000
                                    ^^ MAC address leak

UUID v4 Security:

✅ Completely random, no information leakage

UUID v7 Balance:

Timestamp reveals approximate creation time (not a security issue for most uses). Random component prevents tracking.

Recommendation: Never use v1 for user-facing IDs. Use v4 or v7.

Which UUID Version Should You Use?#

Use UUID v7 when:

  • Building a new application
  • Database primary keys (especially PostgreSQL, MySQL)
  • High write volume
  • Distributed systems needing sortable IDs

Use UUID v4 when:

  • Maximum compatibility needed (older systems)
  • Low write volume (< 1000/sec)
  • Public-facing IDs requiring no pattern

Avoid UUID v1 when:

  • IDs are public-facing (privacy risk)
  • User tracking is a concern

Quick Rule: v7 for new projects with databases. v4 for legacy compatibility. Never v1 for user IDs.

Frequently Asked Questions

Can UUIDs collide?
Theoretically yes, but the probability is so low it is effectively zero. UUID v4 has a 1 in 5.3 × 10^36 chance of collision. You would need to generate 1 billion UUIDs per second for 85 years to have a 50% chance of one collision.
Should I use UUIDs as primary keys?
Yes, but use v7 or v1, not v4. Random UUIDs (v4) cause severe database performance issues at scale. Sequential UUIDs (v7) work great as primary keys.
Is UUID v7 production-ready?
Yes! The RFC was finalized in 2024. Major libraries now support v7. It is the recommended choice for new applications.
How do I migrate from v4 to v7?
Start generating new IDs with v7 immediately. Existing v4 IDs can remain—both can coexist in the same column. Over time, new records will use v7 and benefit from better performance.
Can I extract the timestamp from UUID v7?
Yes! The first 48 bits are the Unix timestamp in milliseconds. Libraries provide functions to parse it, or you can extract it manually.
Why not just use auto-increment integers?
Auto-increment requires coordination (single database). UUIDs allow distributed generation without conflicts—essential for microservices, offline apps, and merging databases.

Generate UUIDs Instantly

Use our free UUID generator to create v1, v4, or v7 UUIDs. Perfect for development and testing.

Try UUID Generator