educative.io

Educative

"Whenever there is a cache miss, our servers would be hitting a backend database. Whenever this happens, we can update the cache and pass the new entry to all the cache replicas"

What do you mean by ‘we can update’ - we who?

The Database is not an ‘active entity’ - it cannot do stuff on it’s own - it only responds to queries. So ‘it’ cannot update the cache.

Why not always read from the caching service?
The caching service may be designed to return the shortened URL if present in the cache. If not present in the cache, the caching service may read from the DB and update the cache and then return the entry (updating the cache may be performed lazily)

The other way is that the application service may be entrusted with the responsibility of updating the cache when there’s a miss!


Course: Grokking the System Design Interview - Learn Interactively
Lesson: Designing a URL Shortening service like TinyURL - Grokking the System Design Interview

Hi @Narayan_Subramanian, we are glad you reached out to us.

Here ‘we can update’ means the server as depicted in the slides in the explanation section. Whenever there is a cache miss the server will request data from the database and upon receiving data, the server will update the cache as well. The database is not connected to the cache for simplicity and in order to keep the cache and database directly connected to the server. This caching technique is called Cache Aside. In this caching, the cache has less load while the technique that you are referring to is called Read Through where the cache is responsible for each data request, if data is not in the cache, then it looks for data in the database and upon successfull data retrieval cache updates itself and then forwards the data to the server. Both caching techniques are valid and implementable, it just depends on what is suitable under given circumstances.

We hope Educative has helped you in your learning experience :slight_smile:

Yes Noor,

Thank you for your response. File Systems implement a read through cache (I know Windows does). The request (read or write) is always served via the cache. In a way it simplifies the responsibilities of the caller. But yes, there may be circumstances where the Cache Aside technique may be more suitable

Thank you again.

Regards,
Narayan


Course: https://www.educative.io/courses/grokking-the-system-design-interview
Lesson: Designing Dropbox - Grokking the System Design Interview