Ask HN: What is the best way to use a URL shortener for my site?
Have an MVP for a particular use case that we're building and we expect to have it all done by around the end of the year. One service that we provide can allow users to share something to others. The way we are generating the link to share right now generates very long urls since we are storing some images on Firebase and when sharing a combination of those we are combining those urls to create a unique sharing link. Is there some smarter way we can use to shorten the links here?
If not, and we end up using a url shortening service, is the best way to self host our own service (we currently use mongoDB for our application and can theoretically do it) or to use an existing service? If existing service is ideal for us, some recommendations would be helpful.
5 comments
[ 2.9 ms ] story [ 25.9 ms ] threadJust 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?
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.