UUIDs v4 and v7, in batches
Generated client-side from crypto.getRandomValues. V4 is the standard random UUID. V7 is the newer time-ordered variant — sorts chronologically, ideal for database primary keys without index churn.
About UUIDs
A UUID (Universally Unique Identifier) is a 128-bit value that you can generate anywhere — on any machine, at any time — without coordinating with a central registry, and still be confident it will not collide with another UUID generated somewhere else.
How UUIDs avoid collisions
A UUIDv4 is essentially 122 random bits packed into a standard 36-character string format. The collision probability is so low that you would need to generate roughly 2.71 × 1018 of them before reaching a 50% chance of a duplicate. Even at a billion UUIDs per second, that takes 85 years.
UUIDv7: timestamp-prefixed
UUIDv7 (standardized in RFC 9562, 2024) replaces the first 48 bits with a millisecond timestamp. The result is still 128 bits, still globally unique, but it now sorts naturally by creation time. This is a major win for database performance — random UUIDv4 inserts cause severe index fragmentation in PostgreSQL and MySQL, while UUIDv7 inserts are append-mostly.
When to pick which
Use UUIDv7 for any new primary key in a relational database, append-only logs, or distributed event streams. Use UUIDv4 when you specifically need unpredictability (session tokens, anti-enumeration handles, anti-CSRF). Use ULID or KSUID if you want shorter, base32-encoded sortable IDs without the UUID format constraints.
Related tools and reading
Password Generator for secrets that need to be human-typeable. Our 1,600-word deep dive on UUIDv7 vs UUIDv4 covers the database benchmarks. Every UUID generated here uses the browser's crypto.getRandomValues() WebCrypto API — nothing leaves your machine.