News for hackers. Stuff that matters.
Re:Ask HN: What is the best way to use a URL shortener for m... by solardev on Thursday August 29, 2024 @12:29PM (#41392557)
> we are combining those urls to create a unique sharing link.

Just hash them into something shorter? You can calculate the risk of collisions based on the expected volume of files/users, or since you control all the hashes anyway, you can just do a quick lookup to make sure that particular hash doesn't exist already? If you want to do something more human-readable, you can also consider "gyfcat" style URLs or look up "adjective adjective animal" hashers like https://cli.r-lib.org/reference/hash_animal.html

Or use a UUID?

Re:Ask HN: What is the best way to use a URL shortener for m... by bobblemouse on Thursday August 29, 2024 @11:46PM (#41397570)
Ah yes this is a good point thank you. Can probably just using a hashing function and perform a quick lookup to avoid collisions as you suggest. If there is a collision what would you suggest is the best way to deal with it? Anything else we should keep in mind when doing this?
Re:Ask HN: What is the best way to use a URL shortener for m... by solardev on Friday August 30, 2024 @01:23PM (#41402756)
It would be easier just to use a longer hash with fewer chances of collisions.

In the past, for non cryptographic uses, I've also just appended two hash algorithms one after the other, figuring that the same collision between two algorithms would be exceedingly improbable.