ULID: Universally Unique Lexicographically Sortable Identifier

https://news.ycombinator.com/rss Hits: 6
Summary

The UUID format is a highly popular and amazing standard for unique identifiers. However, despite its ubiquity, it can be suboptimal for many common use-cases because of several inherent limitations:It isn鈥檛 the most character efficient or human-readable.UUID v1/v2 is impractical in many environments, as it requires access to a unique, stable MAC address.UUID v3/v5 requires a unique seed.UUID v4 provides no other information than true randomness, which can lead to database fragmentation in data structures like B-trees, ultimately hurting write performance.Few projects I worked on used the ULID (Universally Unique Lexicographically Sortable Identifier), and I really enjoyed working with it, and would love to share this experience with you. Specifically for Go programs using Postgres database. But the same applies to other languages or databases too.You can find the full spec here - github.com/ulid/speculid() // 01ARZ3NDEKTSV4RRFFQ69G5FAVULID addresses the drawbacks of traditional UUID versions by focusing on four key characteristics:Lexicographically sortable. Yes, you can sort the IDs. This is the single biggest advantage for database indexing.Case insensitive.No special characters (URL safe).It鈥檚 compatible with UUID, so you can still use native UUID columns in your database, for example.ULID鈥檚 structure is key to its sortability. It is composed of 128 bits, just like a UUID, but those bits are structured for function: 48 bits of timestamp followed by 80 bits of cryptographically secure randomness. 01AN4Z07BY 79KA1307SR9X4MV3 |----------| |----------------| Timestamp Randomness 48bits 80bitsThe power of ULID is its seamless integration into existing systems, even those relying on the UUID data type. Here is a demonstration using Go with the popular pgx driver for PostgreSQL and the oklog/ulid package.The code below first connects to a running PostgreSQL instance and creates a table where the primary key is of type UUID. We then insert records using both standard UU...

First seen: 2025-12-09 21:30

Last seen: 2025-12-10 02:31