Re:Nanosecond timestamp collisions are common
by jstanley on Friday July 21, 2023 @05:17AM
(#36811722)
You need 2 fields anyway, unless you want to have to brute force your hash function when you need to invert it.
Re:Nanosecond timestamp collisions are common
by wongarsu on Friday July 21, 2023 @09:34AM
(#36813565)
Store 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.
Re:Nanosecond timestamp collisions are common
by jstanley on Friday July 21, 2023 @11:17AM
(#36814804)
That'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?
Re:Nanosecond timestamp collisions are common
by wongarsu on Friday July 21, 2023 @11:27AM
(#36814920)
Good 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.
Re:Nanosecond timestamp collisions are common
by iforgotpassword on Friday July 21, 2023 @01:51PM
(#36817072)
I 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.
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.