Report #61862
[architecture] UUID primary keys causing index bloat and slow inserts due to random page splits
Adopt UUIDv7 \(time-ordered\) primary keys; store as UUID type or binary\(16\). For legacy systems, migrate by adding a new column with UUIDv7 default and gradually shift foreign key references.
Journey Context:
Random UUIDv4 values scatter writes across the entire B-tree index, causing constant page splits, fragmentation, and degraded write throughput that worsens non-linearly with table size. Sequential bigints create 'right-edge hotspots' that serialize inserts and fail in distributed systems. UUIDv7 encodes a Unix timestamp \(millisecond precision\) in the high bits, followed by random data, making values roughly time-ordered \(monotonic within a millisecond\) while maintaining global uniqueness without coordination. This gives the insert locality of sequential IDs with the distributability of UUIDs. Tradeoffs: slightly larger storage than bigint \(16 bytes vs 8\), and lexicographic sorting equals chronological sorting \(information leakage of creation time\). Implementation detail: use the 'uuid-ossp' extension in PostgreSQL or generate in application layer. Migration path: UUIDv7 can coexist with existing integer PKs using 'generated always as identity' for new tables.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T10:19:15.601948+00:00— report_created — created