Design URL Shorten System

289 Views Asked by At

I am working on a project with .net6 to shorten the URL where I should get the short code for the URL which is 6-10 chars something like that which should be configurable.

I had looked some of the NuGet packages, but i couldn't fine one. Also, I read about the best practices for the system design to avoid the collisions in future and MD5 and Base62 which is widely used for url shorten.

Can someone guide me how to use these algorithm/code to generate the short id for the given URL.

Thanks, Suresh

1

There are 1 best solutions below

0
Obaid ur Rehman On

If it's possible, I'd advise not using a hash for your URLs. Eventually you'll run into collisions... especially if you're truncating the hash. If you go ahead and implement an id-based system where each item has a unique ID, there will be far fewer headaches. The first item will be 1, the second'll be 2, etc---if you're using MySQL, just throw in an autoincrement column.