educative.io

Do we index hash('key') or 'key' in the databases and caches?

“like Memcached, which can store full URLs with their respective hashes” in (8. Cache) and “(PK) URL.Hash” in 5. Database Schema, though just in 6b. Generating keys offline we were talking about keys, not hashes of keys anymore.

So, how do we look up the long-format of the URL - by hash(‘key’) or the ‘key’? Which of the two is the PK?

Hi @P_M_Lucaci
The 6th heading Basic System Design and Algorithm explains two different ways that how to generate a short and unique key for a given URL.

In 6b: Generating keys offline only describes one of the ways that generates random six-letter strings beforehand and stores them in a database (let’s call it key-DB). Whenever we want to shorten a URL, we will take one of the already-generated keys and use it. This approach will make things quite simple and fast. Not only are we not encoding the URL, but we won’t have to worry about duplications or collisions. KGS will make sure all the keys inserted into key-DB are unique.

So, don’t compare it with others, every approach has a different significance, pros, and cons. Some of them use full URLs with their respective hashes, some deal with keys only, and some have PK URL hash.

Hope it will help, Thank you :blush:

2 Likes

Hi! I am not sure if this answers my questions, because I was not comparing them… What I was asking was, which of them did the article go ahead with? Given different ones were applied in different parts, which makes it confusing because it does not make the writing consistent.

Hi @P_M_Lucaci

My name is Shahrukh Naeem. I hope everything is going well with you. Thank you for reaching out about this. I will try my best to answer your query!

The course covered a variety of approaches, each with its own relevance, benefits, and drawbacks. The goal of the course is to employ each strategy in various contexts to explain practical examples regardless maintaining consistency in the writing.

I hope that this guide is helpful. Remember that I am always available via message to help you with any difficulty you might encounter.

Regards,

Happy Learning :slight_smile:

2 Likes