Earlier quoted context omitted.
What drives me nuts is people storing uuids in databases as hex strings. They're bytes, and if you do it right, even the type 1's are lexigraphically sortable.
Hex strings may require more storage, but they remove the need to convert back and forth and make it easier to manually query the database when debugging. The best type is your database's uuid type if it has one.
Why Choose ULIDs over Traditional UUIDs or IDs for Database Identification?
61–70 of 77 posts
Re: Why Choose ULIDs over Traditional UUIDs or IDs for Database Identification?
#62Earlier quoted context omitted.
There’s no reason to use hex though. Base32/36/62/64 should be considered.
there's no reason to not use hex, though. In my post this is replying to, I mentioned "in lots of databases you can do some sql like TIMESTAMP_MILLIS(CAST(CONCAT("0x", LEFT(REPLACE(id, '-', ''), 12)) AS INT64)). This is a massive advantage over systems that use non-hex encodings." I've had struggles with binary and base62 encodings and things and just want everyone to use hex. Typical databases compress rows or colum…
Storage tends to be cheap, so it's less about that, and more about memory consumption and index efficiency. The cost of transforming back to and from binary is also pretty trivial on modern systems.
Re: Why Choose ULIDs over Traditional UUIDs or IDs for Database Identification?
#63At this point I think that ideal setup is to use numerical id for primary and foreign keys and maintaining a separate uuid field for everything else. The reason being that index size matters a lot (for caches and other things) and index size depends on underlying field size, obviously. Whether to use UUID or ULID is depends on tooling. While it's not hard to write ascending UUID generator and I did it myself few time…
Or you can just store the UUIDs as bytes like the almighty intended.
Even for huge tables 64 bits are enough. And for many tables 32 bits is more than enough.
Re: Why Choose ULIDs over Traditional UUIDs or IDs for Database Identification?
#64Earlier quoted context omitted.
Isn't that basically a type 4 UUID that you truncated the last 4 bytes from?
The encoding is completely different? And given that encoding I don't go to any great means to store them as a special type in the db - just text. uuid being hexidecimal, databases often want to store them as binary since that's half the bytes...
Re: Why Choose ULIDs over Traditional UUIDs or IDs for Database Identification?
#65At this point I think that ideal setup is to use numerical id for primary and foreign keys and maintaining a separate uuid field for everything else. The reason being that index size matters a lot (for caches and other things) and index size depends on underlying field size, obviously. Whether to use UUID or ULID is depends on tooling. While it's not hard to write ascending UUID generator and I did it myself few time…
would you still keep a uniqueness constraint on the uuid/ulid column?
Re: Why Choose ULIDs over Traditional UUIDs or IDs for Database Identification?
#66Earlier quoted context omitted.
Or you can just store the UUIDs as bytes like the almighty intended.
UUID is 128 bits. Even for huge tables 64 bits are enough. And for many tables 32 bits is more than enough.
Re: Why Choose ULIDs over Traditional UUIDs or IDs for Database Identification?
#67Earlier quoted context omitted.
UUID is 128 bits. Even for huge tables 64 bits are enough. And for many tables 32 bits is more than enough.
Oh, 32-bits is enough for a lot of tables assuming you have a transactional ID allocator. The whole reason to have a UUID is so you don't have to serialize all your ID allocation. Agreed though that for some lower volume systems, 64-bits is likely enough to make collisions statistically unlikely.
Re: Why Choose ULIDs over Traditional UUIDs or IDs for Database Identification?
#68Re: Why Choose ULIDs over Traditional UUIDs or IDs for Database Identification?
#69Earlier quoted context omitted.
Or just use ints and encrypt them when you want to return them to the user. https://sqids.org/
I like the general idea, but the page you linked explicitly states that it isn't meant to be used to hide (user) IDs, or actually encrypt data.
Re: Why Choose ULIDs over Traditional UUIDs or IDs for Database Identification?
#70Earlier quoted context omitted.
Or just use ints and encrypt them when you want to return them to the user. https://sqids.org/
NB: may be more accurate to call this hashing, versus encryption