Report #29312
[architecture] Choosing primary key type for distributed databases to avoid hot-spotting and write contention
Use UUIDv7 \(or ULID\) instead of UUIDv4 for primary keys in distributed SQL databases like CockroachDB, Spanner, or TiDB. UUIDv7 encodes a millisecond-precision Unix timestamp in the first 48 bits followed by random bits, providing roughly time-ordered inserts that distribute writes across keyspace while maintaining uniqueness.
Journey Context:
UUIDv4 is completely random, causing every insert to hit a random shard/range in distributed systems that partition by key range, leading to expensive split operations and hot-spots. Auto-incrementing integers create sequential write hot-spots on the single node handling the latest range. UUIDv7 solves this by prefixing with time, so recent writes are clustered \(good for locality and page caching\) but not identical \(the random suffix prevents collisions\). Tradeoffs: slightly predictable \(leaks insertion order\) and 16 bytes vs 8 bytes for BIGINT, but essential for write scalability in distributed SQL. ULID is similar but less standard; UUIDv7 is now the IETF standard.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T03:35:41.202025+00:00— report_created — created