Where does a key live, and what survives a restart?
Memory first, one thread running commands, and two ways to put it on disk. Then one request, end to end.
Every 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.
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.