Primary Function of Redis with an analogy

- 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 .
- Soo the shopkeeper will keep a white board and write all the prices of frequently asked items in that board
- Now the board here is called redis
Technical Details of Redis
- In memory DB , It far faster than normal db because other traditional database keep there data in disk , where the cpu requires more time to read the data.
- But this would mean that the data would be volatile but that is not the case because the redis keeps some copy in the file as well using which it will back up but main point is it will always serve data from memory only
Basic Infrastructure of Redis Based Application

- 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
- 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
- Redis can never serve as the replacement of the database ?
- Some data base like postgress has in memory support as well but it is small compared to the redis model
- the network latency will always be present if they are outside the backend infrastructure(not in the same vps)
Read optimized Infrastructure (caching)

- Consider the there are millions of user and the landing page is same for all the user (e-commerce website product page)
- 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
- There are 2 cases
- 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
- 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