Why is Redis so fast, and what do you give up for it?
This page is about an in-memory data structure server. I show you where Redis keeps your data (memory first, disk second), the two ways it saves to disk, and why one busy key or one big key can slow everything down. After it you will be able to pick a persistence setting, size its memory, and find the key that is hurting you.
A data structure server that keeps everything in memory: strings, hashes, lists, sets, sorted sets and streams, each with its own commands.
Good at: Answers in a fraction of a millisecond. Counters, sessions, rate limits, leaderboards, small queues and caches.
Runs as: one redis-server process per node; Sentinel or Redis Cluster for failover and shardingEvery command runs on one main thread, in memory. Disk is only for getting the data back after a restart; nothing is read from disk while serving.
The same layers as a still diagram, with every part named:
Request path
| Place | What it holds | What to watch |
|---|---|---|
| Memory, the dataset | every key and value | used_memory against maxmemory. When it is full, maxmemory-policy decides: refuse writes (noeviction, the default) or evict keys. |
| dump.rdb | a point-in-time snapshot, written by a forked child (BGSAVE) | While the child writes, every page the parent changes is copied, so a busy server can need much more memory during a save. latest_fork_usec shows how long the fork took. |
| appendonlydir/ (the AOF) | every write command, appended | appendfsync: always, everysec (the default) or no. The AOF is rewritten in the background when it grows. |
| Replication backlog | a ring buffer of recent writes, for replicas that reconnect | Too small, and a replica that drops for a moment needs a full resync: a fork and a copy of everything. |
The usual setup: the AOF on, flushed once a second. Step through it, then tick the box.
Not necessarily. Redis replies before the AOF is flushed, and the flush happens about once a second in the background. Tick the box in the widget to see what a power failure in that second does.
| Setting | Default | What it trades |
|---|---|---|
| appendonly | no | Off: only snapshots, so a crash loses everything since the last one. On: every write is logged. |
| appendfsync | everysec | always: a disk flush per write, safest and slowest. everysec: up to about a second of loss. no: the operating system decides, often about 30 seconds. |
| save | 3600 1 300 100 60 10000 | When RDB snapshots run: after an hour if 1 key changed, 5 minutes if 100, a minute if 10,000. |
| maxmemory | 0, no limit | Always set it, below the machine's memory, leaving room for the fork during a save. |
| maxmemory-policy | noeviction | For a cache: allkeys-lru or allkeys-lfu. For data you must keep: noeviction, and an alert on memory. |
| WAIT and min-replicas-to-write | not used | WAIT makes one client wait until replicas have a write; min-replicas-to-write makes a primary refuse writes without replicas. Both narrow the loss window; neither makes Redis strongly consistent. |
| What happens | What you see | What I do |
|---|---|---|
| A big key | One DEL or HGETALL on a hash with millions of fields blocks every client for hundreds of milliseconds | Find it with redis-cli --bigkeys and MEMORY USAGE. Split it into smaller keys. Delete big keys with UNLINK, which frees memory in the background. |
| A hot key | One shard at 100% CPU while the others idle | A key lives on one shard and one thread. Spread it over several keys, or count in the application and write once a second. |
| KEYS * or a long Lua script in production | Everything stalls while it runs; SLOWLOG fills up | SCAN instead of KEYS. Keep scripts short. |
| Memory full | With noeviction, writes fail with an OOM error. With an eviction policy, keys quietly disappear | Set maxmemory and a policy that matches the job. Alert well before the limit. |
| A fork on a big, busy instance | Latency spikes during snapshots and AOF rewrites; memory jumps; sometimes the out-of-memory killer | Leave memory headroom, turn off transparent huge pages, and take snapshots on a replica. |
| A replica that keeps falling behind | Full resync loops: fork, copy everything, fall behind again | A bigger repl-backlog-size and client-output-buffer-limit for replicas. |
| Failover with asynchronous replication | The newest writes, already acknowledged, are missing after a replica is promoted | Keep only data you can rebuild in Redis, or accept and document the window. |
Type commands as you would in redis-cli. Pick an example to see a session store, a leaderboard and a rate limit built from a handful of commands, then change them.
They wait. KEYS walks the whole keyspace on the one main thread, so every other command queues behind it, often for seconds. SCAN returns a few keys per call and lets other commands run in between.
redis-cli INFO memory # used_memory, maxmemory, mem_fragmentation_ratio redis-cli INFO persistence # rdb_last_bgsave_status, aof_enabled, aof_delayed_fsync, latest_fork_usec redis-cli INFO replication # role, connected replicas, offsets redis-cli CONFIG GET appendfsync redis-cli --bigkeys # the biggest key of each type, by sampling redis-cli MEMORY USAGE cart:42 # bytes for one key redis-cli SLOWLOG GET 10 # the slowest recent commands redis-cli LATENCY DOCTOR # what caused recent latency spikes
Versions and licences. Redis 7.4 moved to source-available licences (RSALv2 or SSPLv1). Valkey forked from 7.2.4 under the BSD licence in 2024, at the Linux Foundation, and AWS and Google Cloud offer managed Valkey. Redis 8 (2025) added AGPLv3 as an option, bundles JSON, search, time series and probabilistic types, and adds a vector set type. The current line is Redis 8.12 (November 2026). Everything on this page about memory, persistence and replication works the same in Valkey.
Your sessions live in Redis with appendfsync everysec and one replica. The primary's machine loses power and the replica is promoted. What do users notice? Is that acceptable for sessions? For shopping carts?
Write your answer down first. Then open mine.
What they notice: writes from about the last second can be gone, and more if the replica was lagging, because replication is asynchronous. Some people who just logged in are logged out; some last cart changes are missing.
Sessions: acceptable. The cost is a re-login.
Carts: annoying but survivable if the cart is rebuilt or the order is written to the relational database at checkout. Never keep the only copy of an order in Redis.
If it is not acceptable: use WAIT for the writes that matter, which narrows the window but does not close it, or keep that data in a database that waits for the disk and a standby.
The same mechanism, caches and memory, what a commit promises, elsewhere on the site: in real incidents, in measurements, and in designs.
Pick an answer. You will see whether it is right, and why.
1. With appendfsync everysec, what can a power failure lose?
Redis flushes the AOF about once a second in the background, so writes acknowledged in that second can be lost.
2. Why can one slow command slow down every client?
Commands run one after another on the main thread, which is also why each command is atomic.
3. Memory reaches maxmemory and the policy is noeviction, the default. What happens to a SET?
noeviction refuses writes that need memory. For a cache, an LRU or LFU policy evicts instead.
4. Why can a snapshot on a busy 40 GB instance need much more than 40 GB?
Copy-on-write: the more the parent writes during the save, the more pages are duplicated.
How do databases actually work? From one row on disk to transactions: the words you need, PostgreSQL, MySQL and MongoDB from the files up, then Redis, Cassandra and vector search, side by side, and the query and concurrency traps.