Report #71805
[architecture] High write amplification and index fragmentation when using UUIDv4 as primary key in B-tree databases
Use UUIDv7 \(time-ordered\) instead of UUIDv4 \(random\) for primary keys to maintain insertion locality, reduce page splits, and improve cache hit rates. Generate in application or use database extensions supporting RFC 9562.
Journey Context:
UUIDv4 \(random\) causes 'index bloat' in B-trees \(InnoDB, PostgreSQL\) because inserts are random I/O, causing frequent page splits and vacuum/optimize requirements. ULID and UUIDv6/v7 were created for this. UUIDv7 \(RFC 9562\) is now standard, encoding timestamp in first 48 bits. Tradeoff: Slightly less entropy than v4 \(not an issue for uniqueness at scale\), but predictable ordering can leak insert rates \(usually acceptable for PKs\). Alternative: bigint with snowflake IDs \(KGS\) if you need strict non-derivability.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T03:06:40.717858+00:00— report_created — created