Menu

Post image 1
Post image 2
Post image 3
1 / 3
0

The Better Primary Key: A Guide to ULIDs for Rails Developers

DEV Community: ruby·Zil Norvilis·3 days ago
#migNOJTB
#dev#fullscreen#ulid#product#ulids#article
Reading 0:00
15s threshold

In a previous article, I talked about Snowflake IDs . They are great, but they require a bit of configuration because you need to manage "Worker IDs." If you want something simpler that gives you the same benefits - secure URLs and fast database sorting—you should look at ULIDs (Universally Unique Lexicographically Sortable Identifiers). Why not just use UUIDs? Most developers switch from auto-incrementing integers to UUIDs because they want to hide their business volume. If your order ID is order/550e8400-e29b... , no one knows if you have 1 customer or 1 million. But UUIDs have a major problem: they are completely random. When you insert millions of random UUIDs into a database, the "B-Tree" index gets fragmented and slow. Your database has to jump all over the hard drive to find where to put the new data. ULIDs fix this. A ULID is 128 bits (just like a UUID), but the first part of the ID is a timestamp . This means ULIDs are chronological. They are unique like a UUID, but they sort like an Integer.…

Continue reading — create a free account

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

Read More