4 ms·
Yes, I tend to like this philosophy in database design, of internal sequential ids which are used for joins between tables etc. and an exposed "external referen
by cacheyourdreams 3y ago
Yes, I tend to like this philosophy in database design, of internal sequential ids which are used for joins between tables etc. and an exposed "external reference". But I typically would use a UUID for my external reference rather than a hash of the internal id.
- newaccount74 3y agoDoesn't that just add a whole lot of unnecessary complexity? If elements have multiple IDs, one of which should not be leaked to the outside, that's just asking for trouble in my opinion. Is generating UUIDv4 or UUIDv7 really too much effort? I'd assume that writing the row to the database takes longer than generating the UUID.
- iforgotpassword 3y agoIt also means once your hash function leaks for whatever reason or gets brute forced because of whatever weird weakness in your system, it's game over and everybody will forever be able to predict any future ids, guess neighboring ids, etc., unless you're willing to change the hash and invalidate all links to any content on your site. If I'm in a scenario where I think I need consecutive ids internally and random ones externally, I'll just have two fields in my tables.
- jstanley 3y agoYou need 2 fields anyway, unless you want to have to brute force your hash function when you need to invert it.
- wongarsu 3y agoStore just the sequential id, compute the hash on the edge. This keeps your database simple and performant, and pushes complexity and work to the backend servers. This can be nice because developers are typically more at home at that layer, and scaling the backend can be a lot easier than scaling your database. But it also comes with the downsides listed in this thread.
- jstanley 3y agoThat's fine, but when a request comes in referencing only a hash and not an id (because you're not leaking ids to clients), how do you get the id?
- wongarsu 3y agoGood point. Back when we did that we just used a reversible hash function (some would call it encryption). There are some simple algorithms meant for encrypting single integers with a reasonable key.
- iforgotpassword 3y agoI might be misremembering, but didn't YouTube do this in the early days? So yeah, that was what I was thinking of when replying, not a traditional hash function.