I have been reading about URL shorteners and there is a common question that I keep running into which I don't understand how to solve for.
Given a long URL, one of the ways to convert it into a short URL:
- Given an id: id
- compute base62(id): shortForm
- store {
id=>shortForm,longUrl} in a database with key being id - return domain/shortForm
Id is either an auto incrementing number or a number chosen from a store of available keys (given scalable needs). However, if Id is chosen in either of those ways, and if I specify https://google.com twice, the algorithm would pick two different id and yield a different shortForm
In most of the services, I have seen that is not the case. I am wondering how is the same shortForm achieved for the same longUrl ?