Hacker News new | ask | show | jobs
by rcoder 41 days ago
If you really need monotonic, secure/unguessable IDs, there are options like CUID2 (github.com/paralleldrive/cuid2).

Older designs like ULIDs (https://github.com/ulid/spec) and Snowflake IDs (https://en.wikipedia.org/wiki/Snowflake_ID) have similar properties to UUIDv7, and potentially some advantages w.r.t. length/encoding/runtime cost/etc.

But UUIDv7 has one key advantage none of those do: you can store them in a UUID-typed column or struct field without any lossy conversion. All of the UUID versions share a common size and serialization format, so it doesn't actually matter if you generate v1/4/7/etc.

Many language standard libraries can generate them interchangeably, and (for example) a Postgres table can store any of the versions in the same column type.

So yes, to the author's point(s): they are not magic, monotonic, un-guessable IDs and you shouldn't treat them as either "secure" or strictly ordered. That doesn't mean they aren't useful.

2 comments

ULID is what I use. I convert it to UUID before storing in PostgreSQL. Technically it's an invalid serialization but it works. The system predates UUIDv7. I also like ULID's shorter representation.
I did that with SQL Server for a time. It was particularly a strange serialization because I tried to match ULID ordering with SQL Server's UUID sort algorithm.
What is special about Postgres' column type? Is it not just binary(16)?
PostgreSQL's UUID type is convenient. But yes it's pretty much just a 16 byte type.