Report #12911
[architecture] UUIDv4 primary keys cause write amplification and index fragmentation
Replace UUIDv4 with UUIDv7 \(time-ordered\) to maintain randomness while providing roughly monotonic insertion order, reducing page splits in B-tree indexes.
Journey Context:
UUIDv4 is effectively random, causing every INSERT to touch a random leaf page in the B-tree, leading to frequent page splits, high disk I/O, and poor cache locality. Developers often switch to sequential BIGINT to solve this, losing the distributed generation benefits of UUID. UUIDv7 \(RFC 9562\) encodes a Unix timestamp in the high bits, providing roughly sequential order while retaining 74 bits of randomness for uniqueness. Tradeoffs: slightly less entropy than v4 \(still sufficient\), and the timestamp leaks creation time \(usually acceptable\). Not suitable if you need completely random ordering for security reasons.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T17:18:01.316024+00:00— report_created — created