Menu

Unique IDs at scale: auto-increment, UUIDv4, UUIDv7 and Snowflake
📰

Unique IDs at scale: auto-increment, UUIDv4, UUIDv7 and Snowflake

DEV Community: java·Ayush Soni·6 days ago
#XNjAnPgW
#devtojava#devto#dev#bits#database
Long article (1276 words) — no AI summary yet.
Reading 0:00
15s threshold

Choosing an ID format feels like a five-minute decision, and it usually gets five minutes. Then, a few years later, it turns out to have decided how fast your inserts are, whether you can split the database, what your URLs tell competitors, and how easy it is to find things during an incident.

This is a solved problem: there are four well-understood answers, each with a clear sweet spot. Here's how to pick.

What we want from an ID

Unique , obviously, including across services and regions.

Generated without coordination , so creating a record doesn't need a round trip to a central counter.

Index-friendly : new IDs should land near each other in a B-tree index, not scattered randomly.

Roughly time-ordered , which helps indexes and makes "what happened around then?" easy.

Compact enough for your storage and your keys.

Safe to show to users without leaking business information.

No option is best at all six.…

Continue reading — create a free account

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