Redis as a message flow processing platform's large-scale high availability and failover strategy
Redis, as a high-performance NoSQL database, has received more and more attention and use. Especially in the Internet field, Redis is not only used as a cache, but also becomes one of the important infrastructures of the message flow processing platform. For this usage scenario, we need to consider the high availability and failover strategy of Redis to ensure the stable operation of the message flow platform.
High availability of Redis
In order to achieve high availability of Redis, we can use Redis Sentinel or Redis Cluster. Among them, Redis Sentinel supports multiple Redis master-slave nodes and realizes automatic failover by monitoring each other; while Redis Cluster allows multiple Redis nodes to form a cluster to realize automatic data sharding and automatic failover functions.
When using Redis Sentinel for high availability guarantee, we need to pay attention to the following points:
1. At least three Sentinel nodes
Redis Sentinel requires at least three nodes to Perform failover. This is because when Redis Sentinel is running, they will monitor each other. When a Sentinel thinks that a Redis master node is down, it will broadcast this information to other Sentinel nodes. It needs to reach the consensus of more than two Sentinel nodes before it thinks that a Redis master node is down. This Redis master node fails.
2. Multiple Redis master-slave nodes
Redis Sentinel can support multiple Redis master-slave nodes to achieve read-write separation and load balancing. At the same time, multiple Redis master nodes should also be independent of each other to ensure that the downtime of one master node will not affect other master nodes.
3. Time synchronization is required between master and slave nodes
The work of Redis Sentinel requires accurate timestamps for judgment. Therefore, we need to ensure that the time between the Redis master and slave nodes is synchronized. Time synchronization can be achieved through the NTP service.
When using Redis Cluster as the infrastructure of the message flow processing platform, we need to pay attention to the following issues:
1. Number of nodes
Redis Cluster supports up to 16384 nodes. And it is not recommended to use less than 6 nodes. At the same time, we also need to pay attention to the hardware configuration and performance of each node.
2. Automatic data sharding
Redis Cluster will automatically distribute data to each node to ensure that the amount of data on each node is relatively balanced. For users, there is no need to manually perform data sharding, Redis Cluster will automatically manage it.
3. Failover
Redis Cluster also supports automatic transfer in the event of a failure. When a master node in the cluster goes down, Redis Cluster will automatically transfer the data of this node to other nodes and elect a new master node to ensure the availability of the cluster.
Redis’ failover strategy
During the operation of Redis, various failures may occur, such as node downtime, network failure, master-slave synchronization issues, etc. At this time, we need to consider how to implement automatic failover of Redis.
1. Failover of Redis Sentinel
Redis Sentinel can achieve failover in the following ways:
(1) Fault detection
Redis Sentinel will periodically Perform a health check on the Redis master-slave node. When a node goes down or loses contact, Sentinel will mark the node as "suspected to be down."
(2) Quorum calculation
When the Sentinel node discovers that a Redis master node is suspected to be down, it will send a notification to other Sentinel nodes. Most Sentinel nodes think that the master node is down. When the master node is down, the master node will be judged to be truly down.
(3) Elect a new master
When the master node goes down, one of the other slave nodes will be elected as the new master node. At the same time, this new master node also needs to synchronize the data on the old master node.
2. Failover of Redis Cluster
The way Redis Cluster implements failover is different from Redis Sentinel:
(1) Fault detection
Redis Cluster It will detect whether the node is down by collecting heartbeat information between nodes.
(2) Failover
When a master node goes down, Redis Cluster will elect a slave node as the new master node and automatically transfer the data on the old master node to the new master node. At the same time, Redis Cluster will also update the data distribution between each node.
Summary
As the infrastructure of the message flow processing platform, Redis must maintain high availability and failover capabilities. When using Redis Sentinel or Redis Cluster, we need to consider factors such as the number of nodes, master-slave node configuration, automatic data sharding, as well as fault handling strategies such as fault detection and failover to ensure the stable operation of Redis.
The above is the detailed content of Redis as a message flow processing platform's large-scale high availability and failover strategy. For more information, please follow other related articles on the PHP Chinese website!