Report #78803
[architecture] Using UUID v4 as primary key causes index fragmentation and poor write performance in relational databases
Use UUID version 7 \(time-ordered\) or ULID for primary keys; they combine randomness with roughly monotonic ordering, eliminating index page splits while maintaining uniqueness across distributed nodes
Journey Context:
Random UUIDs \(v4\) scatter writes across the entire B-tree index, causing frequent page splits and cache invalidation, which kills insert performance in high-throughput systems. Sequential integer IDs solve locality but leak business metrics and create merge conflicts in distributed setups. UUIDv7 encodes a timestamp prefix \(milliseconds since Unix epoch\) followed by randomness, giving you the locality of sequential IDs with the uniqueness guarantees of UUIDs. Alternatives like ULID or Snowflake IDs work similarly. Crucially, PostgreSQL's BRIN indexes work exceptionally well with UUIDv7, while they fail with random UUIDs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T14:52:03.780802+00:00— report_created — created