UUID v4 vs v7: Which Should You Use as Primary Key?
UUID v4 vs v7 comparison: randomness, sortability, database performance, and when to use each version.
UUID v4 (Random)
- 122 bits of randomness
- Not sortable
- Bad for B-tree indexes (random inserts → page splits)
- Good for: security tokens, session IDs
UUID v7 (Time-ordered)
- 48-bit Unix timestamp + 74 bits random
- Sortable by creation time
- Excellent for B-tree indexes (sequential inserts)
- Good for: database primary keys, event IDs
Try It Free
Use our free online tool — 100% client-side, no data leaves your browser.
Open UUID Generator