What is a UUID / GUID?
A UUID (Universally Unique Identifier), also known as a GUID (Globally Unique Identifier), is a 128-bit label used to uniquely identify records across distributed computer systems without central coordination. Standardized under RFC 4122, UUIDs are formatted as 32 hexadecimal digits displayed in 5 groups separated by hyphens (e.g., f47ac10b-58cc-4372-a567-0e02b2c3d479).
UUID Version 4: Pure Randomness
UUID v4 is the most widely used identifier in web applications today. It is generated using 122 bits of cryptographically secure random data. The probability of generating duplicate UUID v4 keys is so infinitesimally small (1 in 2122) that it is virtually impossible.
Drawback in Databases:
Because UUID v4 keys are completely random, inserting them into database primary keys (like PostgreSQL B-Tree indexes or MySQL InnoDB clustered indexes) causes severe **index fragmentation**. Random keys force the database to constantly split B-Tree pages, reducing write throughput on large tables.
UUID Version 7: Time-Sortable Efficiency
Standardized in 2024, UUID v7 combines a 48-bit Unix timestamp with 74 bits of random data. Because the high-order bits contain an increasing timestamp, UUID v7 keys are naturally time-sortable.
Why UUID v7 is Better for Primary Keys:
- Monotonic Insertion: New records are always inserted at the end of database B-Tree index pages, eliminating page splits and fragmentation.
- High Performance: Delivers the speed of sequential auto-increment integer IDs while maintaining global uniqueness across microservices.
- Embedded Timestamps: You can extract the exact creation timestamp directly from the UUID string without adding a separate
created_atcolumn.
UUID v4 vs UUID v7 Comparison
| Feature / Metric | UUID Version 4 | UUID Version 7 |
|---|---|---|
| Generation Basis | 100% Cryptographic Randomness | 48-bit Timestamp + Random Bits |
| Time-Sortable | No (Random) | Yes (Chronological) |
| DB Index Performance | High Page Fragmentation | Optimal B-Tree Appends |
| Best Use Case | API tokens, session IDs, public URLs | Database Primary Keys & Event Logs |
Generate UUIDs in Bulk Online
Whether you need random UUID v4 keys or time-sortable UUID v7 identifiers for your database migrations, use our free online UUID Generator & Batch Picker. It allows you to generate up to 500 unique UUIDs at once with custom uppercase, lowercase, and hyphen formatting options.
