UUID v4 vs. UUID v1: Primary Key Optimization & Collision Probabilities

Published: June 28, 2026 | Author: Alex Mercer (Database Systems Lead) | Category: Database Architecture

Compare Version 4 pseudo-random UUIDs with Version 1 timestamp-based UUIDs for database performance and unique identifier generation.


A Universally Unique Identifier (UUID) is a 128-bit identifier standardized by IETF RFC 4122 designed to guarantee global uniqueness across distributed database architectures without centralized coordination.

What is a Universally Unique Identifier (UUID)?

A UUID (Universally Unique Identifier) is a 128-bit identifier standardized by IETF RFC 4122. UUIDs are formatted as 32 hexadecimal digits displayed in 5 groups separated by hyphens (8-4-4-4-12 characters, total 36 characters including hyphens). You can generate and inspect both RFC-compliant formats in real-time with our UUID v4 and v1 generator.

Example: 550e8400-e29b-41d4-a716-446655440000


UUID Version 4 vs Version 1 Comparison

FeatureUUID Version 4UUID Version 1
Generation BasisCryptographically Pseudo-Random NumbersHost MAC Address + High-Resolution Timestamp
Privacy / AnonymityHigh (Contains no hardware or time signals)Low (Exposes system clock & network adapter MAC)
B-Tree Indexing PerformanceLow (Random distribution causes page splits)High (Sequential time component improves cache hits)
Collision Rate1 in $2^{122}$ ($5.3 imes 10^{36}$)Virtually zero per physical node

Collision Mathematics of UUID v4

UUID Version 4 allocates 122 bits to pure random entropy (6 bits are reserved for variant and version markers).

The probability $P$ of a collision among $N$ generated UUIDs can be approximated using the Birthday Problem formula:

$P \approx 1 - e^{-\frac{N^2}{2^{123}}}$

To achieve a 1 in a billion ($10^{-9}$) chance of a single collision, a database system would need to generate approximately $1.03 imes 10^{14}$ (103 trillion) UUIDs in total. When generating high-volume primary keys alongside synthetic user profiles, pairing UUIDs with our fake persona generator ensures unique test records without database key collisions.


Best Practices for SQL Database primary keys

  1. Use UUIDv7 or Sequential UUIDs (v1/v6) when writing high-volume B-tree indexed SQL tables (PostgreSQL, MySQL InnoDB) to avoid index fragmentation.
  2. Use UUIDv4 for API tokens, session IDs, client-facing resource URLs, and microservice payload identifiers where hardware privacy and randomness are mandatory.

Generate bulk UUIDs instantly for database seeding using our UUID generator and pair them with multi-table seed records from our random address generator and secure password generator for complete staging environment hydration.