Menu

Post image 1
Post image 2
1 / 2
0

Stop using UUID v4 for database primary keys — UUIDv7 is the 2026 default

DEV Community·engr anees·21 days ago
#aIzYQJS4
#javascript#but#webdev#database#uuid#uuidv7
Reading 0:00
15s threshold

Your B-tree indexes hate UUID v4. They've hated it for years. You probably haven't noticed because the slowdown is gradual — until your table hits 10 million rows and inserts start taking 200ms instead of 5ms. UUIDv7 fixes this. RFC 9562 made it official in May 2024. PostgreSQL 18 ships native support. MySQL 8.4 has a helper. Most ORM and language libraries added v7 in 2024–2025. By 2026, v4 should be the exception, not the default . This post is the "why", the "when", and the "how to migrate without breaking things". The Problem with v4 A v4 UUID is 122 bits of pure randomness: e7d1a8c4-9fe5-4a32-8c7e-3f9d2e8a1c4b Looks fine. Random is what we want, right? Yes — for things that need to be unguessable . No — for things that go into a B-tree index. Why B-trees hate randomness Database indexes (B-tree, which is what Postgres, MySQL, SQLite, MSSQL all use for primary keys by default) work best when new entries arrive in roughly sorted order .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More