educative.io

Introduce a cache in front of our database

To deal with hot tweets we can introduce a cache in front of our database. We can use Memcached, which can store all such hot tweets in memory. Application servers, before hitting the backend database, can quickly check if the cache has that tweet. Based on clients’ usage patterns, we can adjust how many cache servers we need. For cache eviction policy, Least Recently Used (LRU) seems suitable for our system.

are we saying that the index only maps from keyword to tweet id. then, we still need to query the database to get the contents of the tweet? with memcache, load on this database would be reduced.

Hi @Dewey_Munoz

Yes, precisely. The indexing provides TweetIDs against the user query, but we still need to access the tweets from the database. Caching can reduce the database load, hence avoiding searching the TweetIDs in the database already in the cache.