Report #90794
[architecture] Auto-increment hot-spots in distributed DBs; UUIDv4 causes index fragmentation
Use UUIDv7 \(RFC 9562\) for primary keys in distributed systems. It encodes a Unix timestamp \(ms\) in the first 48 bits followed by random data, providing k-sortability \(good for B-tree locality\) while maintaining global uniqueness without coordination. Store as BINARY\(16\) \(MySQL\) or UUID type \(PostgreSQL\) to save space versus VARCHAR\(36\). Avoid ULID if you need strict UUID standard compliance or sub-millisecond precision.
Journey Context:
Auto-increment sequences create write hot-spots in distributed databases \(sharded MySQL, CockroachDB\) because all inserts hit the latest page. UUIDv4 \(fully random\) eliminates hot-spots but causes severe B-tree fragmentation and page splits because inserts are randomly distributed across the entire keyspace, killing cache locality. UUIDv7 provides the optimal tradeoff: time-ordered prefixes mean new inserts are mostly sequential \(like auto-increment\), but the random suffix prevents clock-based collisions in distributed nodes without coordination. Unlike ULID \(128-bit lexicographically sortable\), UUIDv7 is now an IETF standard and fits existing UUID columns.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T10:59:29.279048+00:00— report_created — created