How to ensure high concurrency and availability of Redis? Can you introduce the master slave replication principle of Redis? Can you introduce Redis’ sentry principle? Partial replication of data under master/slave architecture?

Consider how to use Redis to add multiple machines, to ensure that Redis is highly concurrent, how to ensure that Redis does not die directly after the death, i.e. Redis is highly available?

High concurrency

A single Redis can carry QPS ranging from tens of thousands to tens of thousands. For caches, this is generally used to support high read concurrency. Therefore, the architecture is made into a master-slave architecture, with one master and many slaves. The master is responsible for writing and copying data to other slave nodes, and the slave nodes are responsible for reading. All read requests go from the node. In this way, it is also easy to achieve horizontal expansion and support high read concurrency.

High availability

Redis sentry clusters to achieve high availability, sentry is a distributed system, you can run multiple sentinel process in an architecture, these processes use gossip protocols to receive information about the master node is offline, and use the voting agreement to decide whether to implement automatic fault migration, and choose which for node as the new master node. Each sentry periodically sends messages to other sentries, primary nodes, and standby nodes to check whether the sentry is “alive”. If the sentry does not respond within a specified period of time (configurable), the sentry is temporarily considered dead. If most sentries in the “sentry group” report that a primary node is not responding, the system considers the primary node as “completely dead”. Through the algorithm, one of the remaining standby nodes is selected to promote the primary node, and then the relevant configuration is automatically modified.

Data loss during Redis Sentry active/standby switchover

Data loss caused by asynchronous replication: The master->slave replication is asynchronous. Therefore, some data may break down before it is replicated to the slave, and the data may be lost. Data loss due to split brain: a master’s machine