Report #16294
[architecture] Using UUIDv4 as primary keys causes index bloat and write amplification in B-tree databases
Use UUIDv7 \(RFC 9562\) for primary keys to combine time-ordered locality with distributed generation; prefix with a shard identifier if cross-region write latency is critical
Journey Context:
UUIDv4 is random, causing every insert to hit a random leaf page in the B-tree, leading to page splits, fragmentation, and poor cache locality. Sequential IDs solve this but create a single write hotspot and expose row creation order. UUIDv7 embeds a Unix timestamp in the high bits, giving time-ordered locality while maintaining uniqueness across distributed nodes. The tradeoff is slightly larger size \(16 bytes\) vs BIGINT \(8 bytes\), and the timestamp leaks creation time \(usually acceptable\). Avoid UUIDv8 unless you need custom precision; UUIDv7 is the standard solution.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T02:19:24.862381+00:00— report_created — created