Report #55306
[architecture] UUIDv4 primary keys causing index bloat and page splits in write-heavy databases
Use UUIDv7 \(time-ordered\) for primary keys instead of UUIDv4. It encodes a Unix timestamp in the first 48 bits, maintaining lexicographic sort order while preserving global uniqueness without coordination.
Journey Context:
UUIDv4 is random, causing insertions at random B-tree positions, leading to page splits and poor cache locality in databases like PostgreSQL and MySQL. Sequential IDs \(BIGSERIAL\) solve this but leak business volume and require coordination in distributed systems. UUIDv7 \(standardized in RFC 9562\) provides the best of both: monotonic time-sortability for index locality, but randomness in the remaining bits to prevent clock-rollback collisions. Common mistake: using ULID \(non-standard\) or manually prefixing UUIDv4 with timestamps. UUIDv7 is now natively supported in databases like ClickHouse, and libraries are available for all major languages.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T23:19:23.019561+00:00— report_created — created