UUID Versions Explained
- v1 (Timestamp) Based on time + MAC address — sortable but reveals creation time
- v4 (Random) 122 random bits — most popular, no information leakage
- v5 (Namespace) SHA-1 hash of namespace + name — deterministic, same input = same UUID
- v7 (New!) Timestamp + random — sortable like v1 but no MAC address exposure
The Math of Uniqueness
- UUID v4 has 2¹²² possible values (5.3 × 10³⁶ combinations)
- To have 50% chance of collision: generate 2.7 quintillion UUIDs
- At 1 billion UUIDs/second, that takes 86 years of continuous generation
- In practice: you'll never see a collision in any real-world application
Where UUIDs Are Used
- Database primary keys (PostgreSQL has native UUID type)
- Distributed systems where nodes can't coordinate ID assignment
- File names that must be unique without a central registry
- Session tokens, API keys, and correlation IDs in logs
- Bluetooth device pairing, USB device identification
Format Options Explained
- Standard: 8-4-4-4-12 format with hyphens (RFC 4122 compliant)
- No dashes: 32 hex chars — used in URLs, filenames, some databases
- Brackets {uuid}: Microsoft GUID format (Windows registry, .NET)
- Uppercase: Some legacy systems require uppercase hex