educative.io

How check original url exist or not?

to check if original url already exist into system or not, for which we get the request to generate url, do we will look up across our data base,

I know we do partition our database to store original url.
but what are we suggesting here, is original url already exist, then return the already generated shorten url or generate a new one ?

Why are you gonna generate a new shorten url? if you found (based on the hash value of the original url) the url in the db, and the shorten is not expired yet, you return it to the user. Period.

I think in the solution the author didn’t dig more into how to perform the search of the the url in the db deeper. But that is OK.

At least you already know 2 things: you have cache system, and you have partitions, so you can look up “faster” for the url based on the hash to a specific partition.