HACKER Q&A
📣 bobblemouse

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.


  👤 JohnFen Accepted Answer ✓
All I can speak to is my own preference. My preference is that no URL shortener is used at all. But if one has to be used, it's far better for it to be something hosted and run by the service itself rather than farming it out. Farming it out means that data about me is getting shared with some random service provider somewhere, which is automatically problematic.

👤 solardev
> 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?


👤 n0rlant1s
I agree with the other comments here that you're better off just hosting it yourself. Though, if you go down the path of considering commercial services check out y.gy (note: I'm affiliated). It would allow you to see where people are clicking from (Twitter, Reddit, etc.) and where they are clicking (city-level). It _could_ be useful depending on your traction.