Primary Function of Redis with an analogy

image.png

  1. Consider a store where you want to buy a item now the shop keeper does not know the price soo he refers the book where all the prices are written and then he tells the user the price but if this happens 100x per day this is slow and hard to search .
  2. Soo the shopkeeper will keep a white board and write all the prices of frequently asked items in that board
  3. Now the board here is called redis

Technical Details of Redis

Basic Infrastructure of Redis Based Application

image.png

  1. Soo the backend application will check the value whether it exists in the redis store if it exist it will return that to the user
  2. if not it will check it the database and then if it is found it will store the data in redis and return the data to the backend
  3. Redis can never serve as the replacement of the database ?
  4. Some data base like postgress has in memory support as well but it is small compared to the redis model
  5. the network latency will always be present if they are outside the backend infrastructure(not in the same vps)

Read optimized Infrastructure (caching)

image.png

  1. Consider the there are millions of user and the landing page is same for all the user (e-commerce website product page)
  2. Now since all the get request are the same and they will put so much pressure on the data base soooo we will say that all the read request HAVE to pass through the redis itself
  3. There are 2 cases
    1. Cache miss : this happens when the requested data is not present in the data base and the redis will have look up the database and then it will write in the redis
    2. Cache Hit : This happens when the requested data is present in the database using this we can now quickly server the data to the user