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.…