Redis: what one SET command touches
One thread, one event loop: how a command gets in, does its work, and reaches the disk and the replicas afterwards.
- Source
- redis/redis @ fd7710c
- Drawn
- , by an AI agent
What it shows
Redis runs commands on one thread. The diagram shows why that is enough: what a command does is short, and what is slow happens somewhere else.
In. The event loop in ae.c waits until a socket is readable, then calls the handler registered for it. For a client connection that handler is readQueryFromClient, which reads the bytes and parses them into commands. A complete command goes to processCommand in server.c, which checks it and calls the command's own function: setCommand for SET.
The work. SET stores the value in the keyspace with setKeyByLink and queues +OK with addReply. Nothing is written to the socket at that moment. The reply is queued on the client and written out later by writeToClient.
After. A command that changed data is passed on to two places: the buffer of the append-only file and the stream that replicas read. Snapshots take another route. A periodic task decides one is due and forks. The child process writes dump.rdb from the memory it inherited at that instant, so the parent keeps serving.
Where every box and arrow comes from
Before this drawing was accepted, a script looked up each box and each arrow in redis/redis at commit fd7710c (19 November 2026) and failed if one was missing. These are the lines it found.
| From, to | Proof in the source |
|---|---|
| Client → Event looprequest |
|
| Event loop → Networkingreadable |
|
| Networking → Server corecommand |
|
| Server core → String commandscall |
|
| String commands → Keyspaceset key |
|
| String commands → NetworkingaddReply |
|
| Networking → Clientreply |
|
| Server core → Snapshotsave point |
|
| Server core → Append-only filepropagate |
|
| Server core → Replication |
|
| Keyspace → Snapshotfork |
|
| Snapshot → dump.rdbwrite |
|
| Append-only file → appendonly.aofappend |
|
| Replication → Replicastream |
|
| Box | Proof in the source |
|---|---|
| Client | Any Redis client: it is not part of the server's source. |
| Event loop |
|
| Networking |
|
| Server core |
|
| String commands |
|
| Replica | Another Redis server that follows this one. |
| Replication |
|
| Append-only file |
|
| Snapshot |
|
| Keyspace |
|
| appendonly.aof | The append-only file on disk. |
| dump.rdb | The snapshot file on disk. |
How it was made
An AI agent read the project's source at the commit above and drew this page on a WireMagic canvas through Agent Bridge, the same tools any agent gets when you connect it to the app. The result is an ordinary WireMagic file: download it, open it, and move things around.
You can have your own agent do this for a codebase you know. Connect it, then ask it to draw the architecture of the repository.