Report #59698
[architecture] Write amplification and page splits caused by random primary keys \(UUIDv4\) in high-insert B-tree workloads
Adopt UUIDv7 \(or ULID\) for primary keys; the time-ordered prefix ensures monotonic insertion order, reducing random I/O and page splits while maintaining global uniqueness.
Journey Context:
UUIDv4's random distribution forces the database to insert new rows into arbitrary leaf pages of the clustered index, causing frequent page splits, fragmentation, and buffer pool churn \(write amplification\). Sequential BIGINT IDs solve this but expose insertion order and complicate distributed id generation. UUIDv7 \(standardized in RFC 9562\) encodes a Unix timestamp \(milliseconds\) in the high bits followed by random bits, making values roughly time-ordered \(monotonic within a millisecond\). This causes inserts to append to the 'right edge' of the index, mimicking sequential ID performance while retaining the decentralized generation benefits of UUIDs. Be aware that clock skew between nodes can cause slight out-of-order inserts, but this is negligible compared to v4 randomness.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T06:41:31.668185+00:00— report_created — created