RFC 9562 standardised UUID v7 in 2024. Here is when to use each version, why v7 is better for databases, and how to generate both.
RFC 9562 replaced RFC 4122 as the UUID standard in May 2024. It officially standardised UUID versions 6, 7, and 8, which were previously informal proposals. UUID v7 is now the recommended format for database primary keys going forward.
| Property | UUID v4 | UUID v7 |
|---|---|---|
| Randomness | 122 random bits | 74 random bits |
| Time sortable | No | Yes (ms precision) |
| DB index performance | Poor (fragmentation) | Excellent (sequential) |
| Reveals creation time | No | Yes |
| RFC standard | RFC 4122 (2005) | RFC 9562 (2024) |
| Browser/Node support | Native (crypto.randomUUID) | Library needed |
With UUID v4, each new record inserts into a random position in your primary key index. At 10 million+ rows, this causes page splits and fragmentation that slows inserts by 30–70%. UUID v7's timestamp prefix means every new record appends to the end of the index — the same efficient pattern as auto-increment integers, without the coordination overhead.
// JavaScript (using uuid library)
import { v7 as uuidv7 } from 'uuid';
const id = uuidv7();
// Python
import uuid_utils # pip install uuid-utils
id = str(uuid_utils.uuid7())
// Go
import "github.com/google/uuid"
id, _ := uuid.NewV7()