Redis durability: RDB, AOF and when Redis is a database

Caching and Redis Mid-level Python 3.13+ PostgreSQL 17+ Reviewed By Best Latest Apps

Pick the fix

You store user sessions in Redis. Losing about a second of session updates on a crash is fine. Persistence setting?

Options
Hint 1 of 1

How much loss is acceptable?

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A AOF with appendfsync everysec (plus RDB for backups)

Correct. Bounded loss of about a second at modest cost.

With appendfsync everysec, Redis fsyncs the append-only file about once a second, so a crash loses at most about a second of writes. That matches what sessions can tolerate without paying for an fsync per write.

Why not the others?
  • B appendfsync always. Much slower for a guarantee sessions don't need.
  • C No persistence. A restart logs everyone out.
  • D RDB every hour only. Could lose an hour of sessions.

30-second answer

RDB writes point-in-time snapshots; restarts lose everything since the last snapshot. AOF logs every write; with appendfsync everysec (the usual setting) a crash loses up to about a second, with always almost nothing at a large throughput cost. Replication is asynchronous, so a failover can drop acknowledged writes. Redis can be a primary store for data that tolerates that, but money and orders belong in a database with synchronous durability.

Practise saying it · 30 s. No recording, just a timer

Is Redis durable?

Say your answer out loud, then check which of these points you covered:

  • RDB snapshots
  • AOF everysec ≈ 1 s loss
  • Async replication
  • RAM-bound
  • Not for the only copy of money

Deep dive

Use both RDB (fast restarts, backups) and AOF (smaller loss window) when Redis holds data you care about.

WAIT can block until N replicas acknowledge, narrowing but not closing the loss window.

Memory is the limit: the dataset must fit in RAM.

Managed services add multi-AZ replication but keep the same async model.

Common mistakes

  • Storing the only copy of orders in Redis with default settings.
  • Assuming replicas mean no data loss.
  • Forgetting that a cache flush in one environment can wipe 'durable' data that lived there.

Senior take & follow-ups

Explain RDB vs AOF loss windows, async replication, and where Redis should and shouldn't be the source of truth.

Follow-up questions

Think of your answer first, then open the hint.

  1. What does appendfsync everysec risk?

    Show hint

    About one second of writes on a crash.

  2. Does WAIT make Redis strongly consistent?

    Show hint

    No; failover can still promote a replica that missed writes.

Suggest a fix if something here is wrong or out of date.