Report #3751
[architecture] Random UUIDv4 primary keys cause index fragmentation and page splits in B-tree storage
Use UUIDv7 \(time-ordered\) as defined in RFC 9562, or ULID, to maintain roughly monotonic insertion order while retaining global uniqueness without coordination. Avoid UUIDv4 for high-write OLTP tables.
Journey Context:
UUIDv4 provides excellent collision resistance and is easy to generate client-side, but its random distribution causes every INSERT to touch a random leaf page in the clustered index, leading to high page splits, buffer pool churn, and storage bloat \(especially in PostgreSQL where the PK is the clustered index\). Auto-increment BIGINT solves the locality problem but requires a central coordinator or complex snowflake-style schemes in distributed systems. UUIDv7 encodes a Unix timestamp \(millis\) in the high bits followed by randomness, giving monotonic roughly-time-ordered inserts while remaining sortable and unique. This preserves the distributed generation benefits of UUID while giving the storage locality of auto-increment. ULID is a prior art alternative with similar properties but UUIDv7 is now the IETF standard.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T18:10:03.337409+00:00— report_created — created