> UUIDs are crazy overkill in any situation where you can have centralised ID allocation.
Except that’s specifically the use case of UUIDs: to have a decentralized method to generate unique IDs with minimal chance of collisions. If you have centralized control, of course there will be options with more attractive properties: they aren’t dealing with the same constraints.
Re:New UUID Formats
by chrismorgan on Monday June 13, 2022 @12:43AM
(#31721240)
Sure, decentralised allocation is the intent of UUIDs, but in practice UUIDv4 is used extremely widely where it’s completely unnecessary, because it’s a convenient way of generating non-sequential IDs with good tooling support (UUID libraries, UUID data types in some databases, &c.).
I've done something similar to obfuscate private DB IDs in a large existing application - just ensure they're all Skip32-encoded in all query parameters with an app-wide secret.
It works well but you have to be very disciplined to catch every case individually. Using GUID PKs from the start just removes this entire category of problem.
Re:New UUID Formats
by chrismorgan on Monday June 13, 2022 @12:48AM
(#31721274)
If it requires discipline, you’re doing it wrong. For best results, it should be threaded through your ORM or equivalent so that you can’t do it wrong, that at your app layer you never get raw IDs.
Re:New UUID Formats
by yencabulator on Monday June 13, 2022 @04:01PM
(#31730993)
I dabbled with doing that. XTEA is a 64-bit block cipher, which suits 64-bit IDs pretty well, and well you can't really ask for much more without using larger IDs. I use z-base-32 to stringify -- I considered base58, but I think case-sensitive URLs are not nice.
Looks like
user=1 doc=1
-> /users/a7e34gz71r4ig/documents/xs69f1c878rzq
user=42 doc=13
-> /users/am8hng8rnoopg/documents/9othzs4tgujrw
I have the code in Go (it's near-trivial), but ended up doing something else for that project.Also, I hate that Postgres doesn't actually have unsigned integers.
(I am not aware of any open-source library embodying a scheme like what I propose—all that I’ve found have either reduced scope or badly broken encryption; https://github.com/yi-jiayu/presents encrypts soundly, but doesn’t stringify; Hashids is broken almost beyond belief and should not be considered encryption; Optimus uses an extremely weak encryption.)
UUIDs are crazy overkill in any situation where you can have centralised ID allocation. Fully decentralised? Sure, 128 bits of randomness or mixed clock and randomness or similar, knock yourself out. But got a master database? Nah, you’re just generating unreasonably long values that take up unnecessary space and make for messy URLs and such.