Brief Story of Redis

Agus D Prayogo
Life at Telkomsel
Published in
4 min readFeb 13, 2023

Hello Redis

First of all, redis is major known in memory database can be used as a database, cache, and message broker. It is often used because it is very fast, due to the fact that it stores data in memory rather than on disk.
Redis was created by Salvatore Sanfilippo in 2009. Sanfilippo originally developed Redis as a way to improve the performance of a web application he was working on.Redis has gained widespread popularity due to its ability to store data in a variety of data structures, such as strings, lists, sets, and hash tables. It is also known for its support for publish-subscribe messaging, transactions, and its ability to handle high-speed data ingestion.

Since its initial release, Redis has undergone many updates and improvements. It is now widely used in a variety of applications, including real-time analytics, message queues, and distributed caching. It has a large and active developer community and is supported by a number of companies, including Redis Labs, which offers a managed version of the software as a service.

Redis Sentinel, Sharding what’s different

Redis Sentinel and Redis Cluster are two different features that are available in Redis.

Redis Sentinel is a high availability solution that provides monitoring, notification, and failover capabilities for Redis. It allows you to set up a cluster of Redis servers that work together to provide a highly available service.

Redis Cluster, on the other hand, is a distributed data store that allows you to scale out Redis horizontally by sharding data across multiple Redis instances. It works by dividing the keyspace into smaller pieces called shards and distributing the shards across multiple Redis servers.

Both Sentinel and Cluster can be used to improve the availability and performance of a Redis deployment. Sentinel is primarily used for high availability, while Cluster is primarily used for scaling. However, it is possible to use both Sentinel and Cluster together in a Redis deployment to achieve both high availability and scalability.

Even if sentinels and clusters may achieve high availability, there is a fault tolerance limitation: neither can have two active-active clusters, so when one of the clusters fails, the application suffers. Redis enterprise can handle high availability with 2 active-active clusters.

Is autofailover achievable without Redis Enterprise ?

The short answer is yes. Since redis is primarily used for caching, which is non-persistent data, it will be more crucial for availability over consistency. If redis fails, most applications will suffer, but if data lost, the application can still running and retrieve lost data from the primary database / persistent data.

Auto failover Redis via Consul

Redis can achieve auto failover between clusters :

  1. Using Load Balancer / Service Discover
    F5 / Consul can be used in front of a redis cluster / stand alone, when one of them down, it will move to another cluster.
  2. Handling auto failover from backend Service
    In spring boot there is a library for handling failover, this can be implemented for handling redis failover.

Redis failover SpringBoot using Resilience4j

Resilience4j is a lightweight, easy-to-use fault tolerance library for Java 8 and functional programming. It provides a simple API for common fault tolerance patterns such as circuit breaking, retrying, rate limiting, and caching. Resilience4j is inspired by Netflix Hystrix and similar libraries but is designed to be more lightweight and functional.

CircuitBreaker Redis Template

In the graph below, it can be seen that between 10:09–10:10 there was a failed request to the backend, because the backend made a swingover to standby redis.

jmeter result during swingover activity test

What’s Next

Thanks for reading about Redis and all that it can accomplish for you. If you are developing web or mobile applications & heavy usage, I am convinced that Redis will be a handy tool in your stack. Please read the detail doc’s on redis.io or and you can use a tool like redis lab to find your redis key

The Code

The full source code for the samples presented above may be downloaded for free from my git repository below.

https://github.com/agusdwi89/redis-failover

--

--

Agus D Prayogo
Life at Telkomsel
0 Followers
Writer for

Passionate software developer with a strong love for writing clean, efficient, elegant code.