Algorithm for generating urlHash

As an alternative to generating random keys, what about passing the paste contents into a hashing algorithm similarly to tinyURL. e.g. MD5(paste contents) -> 128 bit value -> 64bitEncode(128 bit value) -> then select some number of chars for URL. I forsee a duplicate key issue which can be better solved with KGS but this would be an option to consider right?

1 Like

I had the same question. It’s possible to use MD5, however the computational complexity is O(N), where N is the number of characters in the paste. So if pastes are very long, it may be cheaper to simply generate a random key instead.

Course: Grokking the System Design Interview - Learn Interactively
Lesson: Designing Pastebin - Grokking the System Design Interview