Using random UUIDv4 values as database primary keys looks clean at 100k rows and turns painful past 20M rows. The bottleneck is not UUID size (16 bytes)—it is write locality inside B-Tree indexes.
1. What Random UUIDv4 Does to B-Tree Pages
Sequential keys append to the rightmost leaf page of a B-Tree, so hot index writes stay inside RAM (shared_buffers in PostgreSQL, innodb_buffer_pool in MySQL).
Completely random UUIDv4 keys scatter inserts across the entire index:
- Half-full page splits inflate index size by 30–50% and drive random disk I/O.
- In MySQL InnoDB, because the primary key is clustered and copied into every secondary index, random UUIDv4 keys degrade cache hit ratios across all indexes on the table.
2. How RFC 9562 UUIDv7 Keeps 16 Bytes and Restores Locality
UUIDv7 fits inside the exact same standard UUID column type, placing a 48-bit big-endian Unix millisecond timestamp in the first 6 bytes:
- Bits
0..47: Unix epoch timestamp in milliseconds - Bits
48..51: Version7(0111) - Bits
52..63: 12 bits of sub-millisecond monotonicity / randomness - Bits
64..65: RFC 9562 variant10 - Bits
66..127: 62 random bits
Because keys increase monotonically with time, inserts land at the rightmost leaf pages—and you can decode exact creation timestamps straight out of any UUIDv7 without touching the database.
3. Zero-Dependency CLI & Browser Inspector
I built a small MIT CLI (uuidv7-inspect, zero dependencies, node --test passing) to generate RFC 9562 UUIDv7s and inspect embedded timestamps, paired with client-side browser tools (0 bytes uploaded):
- Open-Source CLI (
uuidv7-inspect, MIT): https://github.com/JangYS0/uuidv7-inspect - Browser UUIDv7 / UUIDv4 Generator & Inspector: https://global-utils.com/en/uuid-generator
- Unix Timestamp Converter: https://global-utils.com/en/timestamp-converter
- UUIDv7 & Snowflake ID Suite: https://global-utils.com/en/assets/uuidv7-snowflake-high-throughput-id-suite

