Redis Replication

7 questions found

What is Redis replication, and how does it help improve availability and read scalability?

Beginner
Redis replication lets you create one or more replica servers that maintain a continuously synchronized copy of a primary server's data, providing a backup that can take over if the primary fails, and also letting you distribute read traffic across the replicas to reduce load on the primary server.
-- On the replica server
REPLICAOF primary_host 6379
Real-world example A busy application directs its read heavy reporting queries to a replica server while all writes go to the primary, reducing the load on the primary server and improving overall responsiveness.

Common follow-ups: Can replicas accept write operations directly?;How much delay is typical between a write on the primary and it appearing on a replica?

Redis Sentinel & High Availability;Cluster Sharding & Hash Slots

How do you configure a Redis instance to become a replica of another Redis instance?

Beginner
You use the REPLICAOF command, specifying the hostname and port of the primary server you want to replicate from, either as a runtime command or as a configuration file setting, after which the replica automatically connects to the primary, performs an initial full synchronization, and then continuously receives ongoing updates.
REPLICAOF 192.168.1.10 6379
-- Or in redis.conf:
-- replicaof 192.168.1.10 6379
Real-world example A team sets up a new replica server by configuring it to replicate from their existing primary, watching it automatically synchronize the entire dataset before beginning to serve read traffic.

Common follow-ups: What happens during the initial full synchronization process?;How do you stop a replica from following its current primary?

Redis Sentinel & High Availability;Persistence (RDB/AOF)

What is replication lag, and what factors can cause a replica to fall noticeably behind its primary server?

Intermediate
Replication lag is the delay between when a write happens on the primary and when that same change is actually reflected on a replica, which can be caused by network latency between the servers, the replica being overloaded with its own read traffic, a slow disk affecting the replica's ability to keep up, or a very high write volume on the primary that outpaces the replica's processing speed.
-- Check replication lag using the INFO command
redis-cli -h replica_host info replication | grep master_repl_offset
Real-world example A team notices their reporting dashboard showing slightly outdated data and discovers their replica had fallen several seconds behind due to unusually high read traffic, prompting them to add an additional replica to better distribute the load.

Common follow-ups: How do you measure the exact replication lag in seconds or in offset?;What is an acceptable amount of replication lag for a typical application?

Redis Monitoring & Observability;Redis Performance Tuning & Benchmarking

What is the difference between full resynchronization and partial resynchronization when a replica reconnects to its primary after a temporary disconnection?

Intermediate
Full resynchronization requires the replica to receive an entirely new complete copy of the primary's dataset, which can be slow and resource intensive for large datasets, while partial resynchronization allows the replica to catch up by receiving only the specific changes it missed during the disconnection, using a backlog buffer the primary maintains, which is much faster and less resource intensive when the disconnection was brief.
-- Check the replication backlog size, which affects
-- how long a disconnection can be tolerated before
-- requiring a full resync instead of a partial one
CONFIG GET repl-backlog-size
Real-world example A replica that briefly loses network connectivity for a few seconds successfully performs a partial resynchronization once reconnected, quickly catching up without needing the time consuming full resync that would have been required for a longer outage.

Common follow-ups: How do you configure the size of the replication backlog buffer?;What determines whether a reconnecting replica can use partial versus full resynchronization?

Redis Architecture & Installation;Redis Sentinel & High Availability

How would you design a read scaling strategy using multiple Redis replicas for an application with a very read heavy workload?

Advanced
You would add multiple replicas and distribute read traffic across them using a client side or proxy based load balancing approach, carefully monitor each replica's lag to ensure read consistency remains acceptable for your application's needs, and consider whether certain reads that absolutely require the most current data should still go directly to the primary rather than a potentially slightly lagging replica.
-- Distribute reads across multiple replicas
-- while directing all writes to the primary
const readClient = getRandomReplica();
const writeClient = getPrimary();
Real-world example A content platform with a heavily read dominated workload adds three replicas and distributes read traffic across them, dramatically increasing their overall read capacity while keeping all writes correctly routed to the single primary server.

Common follow-ups: How do you handle a scenario where a specific read absolutely cannot tolerate any replication lag?;What load balancing strategies work well for distributing reads across multiple replicas?

Clustering;Redis Performance Tuning & Benchmarking

What happens to a Redis Cluster's replicas during a failover event, and how does the cluster decide which replica gets promoted?

Advanced
When a master node becomes unreachable, the cluster's remaining nodes vote among themselves, and if a majority agrees the master has truly failed, one of that master's replicas, typically the one with the most up to date data based on replication offset, is automatically promoted to become the new master for that portion of the hash slots.
-- Failover selection considers each replica's
-- replication offset to choose the most up to date one
redis-cli cluster nodes
Real-world example A cluster automatically promotes the most up to date replica to become the new master within seconds after detecting the original master has failed, minimizing both downtime and the amount of data that might be lost during the transition.

Common follow-ups: What happens if multiple replicas have identical replication offsets during a failover decision?;How long does this automatic failover and promotion process typically take?

Clustering;Redis Sentinel & High Availability

How do you check the current replication status and role of a specific Redis instance, whether it is acting as a primary or a replica?

Intermediate
You use the INFO REPLICATION command, which shows whether the instance is currently acting as a master or a replica, lists any connected replicas if it is a master, or shows the primary it is following along with the current replication offset and lag if it is itself a replica.
redis-cli info replication
Real-world example A team troubleshooting a replication issue checks INFO REPLICATION on both servers, confirming the replica is correctly connected to the intended primary and identifying the current replication offset on each side.

Common follow-ups: What does the role field in this output actually indicate?;How do you interpret the master_repl_offset and slave_repl_offset values together?

Redis Monitoring & Observability;Redis CLI & Basic Commands