Skip to the page

Redis in depth · senior

Redis persistence, replication and Sentinel

Redis can lose data in several ways: a restart without persistence, the last seconds before a snapshot, and asynchronous replication during a failover. Match the setting to the data.

The notes

What you must know

  • RDB: point-in-time snapshots made by a forked child. Compact and fast to load, but you lose everything since the last snapshot. A fork of a big dataset can stall Redis briefly.
  • AOF: a log of every write. appendfsync everysec (the common default) loses up to about a second. always is safest and slowest.
  • Both together is common: AOF for durability, RDB files for backups.
  • Replication is not persistence: if a primary with persistence off restarts empty and its replicas sync from it, they wipe themselves.
  • Replication is asynchronous: the primary acknowledges before replicas have the write, so a failover can lose the last writes. WAIT makes one write wait for replicas, but is still not a guarantee. min-replicas-to-write makes a cut-off primary stop accepting writes.
  • Sentinel: at least 3 processes in different failure zones watch the primary. When enough agree it is down (the quorum), one promotes a replica. Clients ask Sentinel for the current primary.
  • Split brain: an old primary cut off from Sentinels but not from some clients keeps accepting writes. After the network heals it becomes a replica and its separate writes are thrown away. Clients must re-resolve the primary on failover.
  • Picks: a cache needs no persistence. A job queue needs AOF, replicas and noeviction, or a real broker. A leaderboard that is slow to rebuild needs RDB plus AOF. Money must not live only in Redis: a durable ledger comes first.

The red pen

Common traps: mistake → fix

  • Mistake: Redis is in memory, so it cannot persist

    Fix: RDB and AOF exist.

  • Mistake: Replicas are backups

    Fix: an empty primary can wipe them.

  • Mistake: Sentinel guarantees no data loss

    Fix: failover can lose writes.

  • Mistake: AOF always for everything

    Fix: it is slow and needed for few cases.

Easy to hard

Questions interviewers ask, easy to hard

  1. RDB, AOF or no persistence for a cache, a queue and a leaderboard?
  2. How does Redis stay available when a node dies?
  3. About 2,000 wallet credits vanished after a Sentinel failover. How?
  4. What are min-replicas-to-write and WAIT?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview