v4 vs v7 in one paragraph
v4 is 122 bits of randomness — perfectly distributed across the keyspace, which is great for entropy and bad for B-tree indexes (each insert is a random write). v7 prepends a 48-bit millisecond timestamp, so consecutive inserts hit nearby pages and your index stays compact. For new database schemas in 2024+, default to v7 unless you have a specific reason not to.
FAQ
- v4 vs v7 — which one?
- v7 if you control the database. Time-ordered UUIDs are friendlier to B-tree indexes, reducing fragmentation and write amplification. v4 is fine for ephemeral tokens or when ordering doesn't matter.
- Are these cryptographically random?
- Yes. They use
crypto.randomUUID(v4) orcrypto.getRandomValues(v7) — Web Crypto API, CSPRNG. Don't use these as session secrets, but they're collision-safe. - Collision risk?
- For v4: 2¹²² random bits. Generating a billion per second for a century gives ~50% chance of one collision — effectively never. v7 is similar but anchored to time.
- Why isn't v7 in my standard library?
- It's newer (RFC 9562, 2024). Node.js 22+ has it; older runtimes need a polyfill. Major databases (Postgres, MySQL) accept it as a regular UUID.
Related tools
- Base64 Encode / Decode
UTF-8 safe encode and decode that round-trips emoji, CJK, and URL-safe variants.
- URL Encode / Decode
URL encode / decode with three variants: encodeURIComponent, encodeURI, and form-urlencoded.
- Unix Timestamp Converter
Convert between unix timestamps (seconds or ms) and human dates (ISO, RFC, local).
- JWT Decoder
Decode JWT header and payload, see expiration status. No signature verification.