educative.io

Why do we need to hash existing url?

If we have the requirement about different tiny URLs for the same original URL generated multiple times, then why do we need to apply MD5 to existing URL and then encode it? Seems it would be much simpler just to generate new UUID, it would give the 128-bit number too, and we could encode it then.

4 Likes

Hi @Vadim The case of generating varying short URLs using one long URL involves appending the userID to the long URL; it will make sure a unique MD5 output and hence we can encode it. One clarification: repeated short URL generation attempts by a single user will generate the same short URL over and over again. If you were considering the case without the involvement of userID in each iteration, then yes generating a new UUID and encoding it is the most suitable solution.