CodePark/ questions / Replication, Sentinel & Cluster
START PRACTICINGPRACTICE
Backend question · Redis & caching › Replication, Sentinel & Cluster

What should you consider before sending reads to Redis replicas?

The main risk is stale data. Replication is asynchronous, so a replica can be behind the primary. Usually this lag is milliseconds. Under load or after a network problem, it can be much longer. A user who writes and then reads from a replica right away may not see their own write.

Replica reads fit data where slightly old values are fine, like cached pages or leaderboards. For read-your-own-writes paths (a user must see what they just saved), read from the primary. Watch replication lag with INFO replication.

Also keep in mind:

  • Replicas are read-only by default.
  • During a full resync, a replica may serve old data or reply with errors. This depends on configuration.
  • In Cluster, a replica serves reads for its slots only after the client sends READONLY on that connection. Cluster-aware clients have an option for this.
  • Async replication means replicas can return stale data.
  • Paths where users must see their own writes should read from the primary.
  • Replica reads are good for data that can be slightly old.
  • Watch replication lag with INFO replication.
  • In Cluster, replicas need READONLY before they serve reads.