What you're really optimizing for
Primary keys need uniqueness first. After that, teams argue about length, sort order, and whether IDs should be guessable. There is no single winner — pick based on your storage and exposure model.
Quick comparison
Use this as a starting point:
- UUID v4 — ubiquitous, random, not time-sortable; fine for most apps
- UUID v7 — time-ordered, better B-tree locality for recent inserts
- NanoID — shorter, URL-friendly alphabet; great for public slugs
- Avoid sequential integers for public IDs if enumeration is a risk
Generate both on code.live
Generate bulk UUID v4 lists, try UUID v7 when you need sortable ids, or switch to the NanoID Generator when you want shorter public tokens. Copy what you need and move on — no SDK install required for a quick experiment.