UUID v7: The Time-Based Identifier You Should Be Using
Learn why UUID v7 is the best choice for modern distributed systems with its time-ordered, sortable design.
UUID v7 is a new UUID format defined in RFC 9562 that combines the best properties of UUIDs with time-based ordering. It is rapidly becoming the recommended choice for primary keys in databases.
Why UUID v7 Over v4?
UUID v4 is purely random, which causes several problems in practice:
- Poor database index performance: Random UUIDs cause excessive B-tree page splits
- No natural ordering: You cannot sort by creation time without an additional column
- Cache unfriendly: Random distribution means poor locality of reference
UUID v7 solves all of these by embedding a Unix timestamp in the first 48 bits.
Generating UUID v7
// Using the uuid package (v9+)
import { v7 as uuidv7 } from 'uuid';
const id = uuidv7();
// "018ec3e2-7c5a-7d1e-8b3f-4a5c6d7e8f9a"
Database Performance Benefits
Benchmarks consistently show UUID v7 outperforming UUID v4 for indexed columns:
|--------|---------|---------|-------------|
The time-based ordering means new records are always appended to the end of the B-tree index, eliminating random page splits.
Migration Strategy
Moving from UUID v4 to v7 is straightforward since they share the same 128-bit format. Existing v4 UUIDs remain valid — simply start generating v7 for new records.
Use our UUID Generator tool to create UUID v7 identifiers instantly.