Report #14138
[architecture] Index bloat, slow inserts, and high write amplification using UUIDv4 as primary keys in high-write databases
Replace UUIDv4 with UUIDv7 \(RFC 9562\) for primary keys. UUIDv7 encodes a Unix timestamp prefix \(milliseconds\) followed by random bits, providing k-sortability \(roughly time-ordered\) while maintaining global uniqueness. This converts random I/O into sequential appends, reducing B-tree page splits.
Journey Context:
UUIDv4 is completely random, causing every insert to hit a random leaf page in the clustered index, leading to page splits, high disk I/O, rapid index bloat \(especially in InnoDB/MySQL or PostgreSQL\), and poor buffer pool locality. Sequential integers \(BIGSERIAL\) solve this but expose data volume, complicate distributed ID generation \(shard conflicts\), and allow enumeration attacks. UUIDv7 \(standardized in RFC 9562\) provides the best of both: the first 48 bits are a timestamp, making inserts append-only \(like sequential IDs\) while the remaining bits provide uniqueness without coordination. Tradeoffs: UUIDs are 16 bytes vs 8 bytes for BIGINT \(storage overhead\), and UUIDv7 is slightly slower than pure sequential IDs due to random suffix, but significantly faster than UUIDv4 for write-heavy workloads. ULID is a pre-UUIDv7 alternative with similar properties.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T20:45:16.403857+00:00— report_created — created