Mark As Completed Discussion

Redis Use Cases

Redis as a cache instance

Let's look at a simple example where we can use Redis as a cache to improve performance and utilize it to the maximum potential.

Redis Use Cases

Let's say we have a web application that takes too long too retrieve data from a database server. Suppose iit takes from 30 to 60 seconds to perform that operation.

This waiting time is a terrible experience for the user. To fix this problem we can leverage a Redis instance. Now, instead of directly querying the database and waiting 30 to 60 seconds, we can store data in a Redis cache instance and just query that instance running in the system memory (RAM).

The web server will first check if Redis has the data that it requires. If it doesn't have the data, this will be considered a cache miss. The web server will then query the database and retrieve the data that it needs. After that it will populate the Redis instance with that data-- so that the next time it needs to retrieve that data, it will get it from the Redis instance. We call this a cache hit.

This way we will bring down the total wait time to less than 5 seconds or even less than 1 second.

Redis as a multi-model database

Redis can also be used as a fully fledged multi-model database that can be used to store and and keep multiple data formats. Let's look at one case where we would make a lot of things simpler and easier by implementing a database with it.

We have a complex social media application that uses multiple microservices and different types of databases including Relational, Graph and Document type databases, and also a cache.

Redis Use Cases

As we can see all these data services need to be maintained and deployed which means it takes a lot of work, energy and experience to keep them in a good and running state. Another thing which we will face in the future with this architecture is scaling: when scaled all of the mentioned data services will have different requirements which can be an additional challenge for our team.

A good workaround for these problems is to use cloud platforms which comes with a drawback: we will have to pay for each managed data service separately. On the backend, we also face a problem: the application code gets very complex because we have to talk to multiple data services, and for each we need a separate connector and logic. This causes quite a few difficulties like higher latency due to each connection step between the services. This will add some latency to our application, and because of this, testing our application becomes challenging as well.

To solve all of these issues we can Redis as multi-model database. We will have only one data service so our microservices will need to talk to only a single data store, we will have less latency, less complicated code in our backend, we will be able to store multiple type of databases into one. Redis can also additionally act as a cache to improve the performance of our web application.