Welcome to my place where I share what I have learned.

what is redis and some of its use cases

you might have noticed how fast instagram loads pages after the first load. have you ever wondered, why is that so?

it does so simply by storing the query results of the initial load to cache. cache can be considered as a temporary database for retrieving information that is redundantly. this method decreases the cost of database queries and enhances user experience.

something similar to this is redis. redis is an open-source technology that can be used as a cache, database or even a message broker. unlike other data-structure stores, redis is in-memory data structure store meaning it processes operations in-memory (RAM) which makes operations like read and write extremely fast.

where can you use redis?

you can use redis basically everywhere you require extremely fast db queries. for example, consider you want to add rate limiting to your application as a security measure to protect it from abuse. now one way you could do this is caching ip and time inside redis and query it for every request, blocking ips with requests more than the threshold in a set interval of time. imagine doing this same, but in a database service. every query would turn out to be a bottleneck.

one another use case could be message broking and redis queues. you can use redis as a message broker for communication messages super fast. for example, consider you have an application which requires plenty of processing time. in such case you will have to offload the time-heavy task to workers for them to process it in background. this method saves your app from getting blocked and being unresponsive. redis stores the meta data of every task and passes it to workers if they are free or queues them if workers are busy. this way neither you api is harmed nor is the user exp.

yet another use case could be a load balancer. storing the information of VMs like the number of free cores available can help load balancer route request to the VM with least work. load balancing is critical when applications are scaled and require more VMs. if prevents a single VM from suffocating with requests and deliver performance.

if you have read it till here, do give a use case of where you use redis and how you use it.