Quick revision
The short answer
I would budget memory per node well beyond the data: fragmentation of 10 to 30 percent, client and replication buffers, a replication backlog sized for minutes of writes, and copy-on-write during BGSAVE and AOF rewrite, which can approach the dataset size under heavy writes. With persistence, that leads to maxmemory at about 60 to 75 percent of RAM. I would split 120 GB into five or six shards of 20 to 25 GB rather than one large node, set vm.overcommit_memory to 1, keep transparent huge pages off and swap pressure away, and prove the plan with a load test that forks and resyncs under write load.
What to remember
In this answer, we saw that a node must hold far more than its data: fragmentation, client and replication buffers, a backlog sized for minutes of writes, copy-on-write during forks and the operating system. With persistence, maxmemory at about 60 to 75 percent of RAM is a safe rule, and splitting 120 GB into shards of 20 to 25 GB makes forks, resyncs, restarts and failures smaller. vm.overcommit_memory 1, transparent huge pages off and no swap complete the setup, and a load test that forks and resyncs under write load proves it.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would budget memory per node well beyond the data: fragmentation of 10 to 30 percent, client and replication buffers, a replication backlog sized for minutes of writes, and copy-on-write during BGSAVE and AOF rewrite, which can approach the dataset size under heavy writes. With persistence, that leads to maxmemory at about 60 to 75 percent of RAM. I would split 120 GB into five or six shards of 20 to 25 GB rather than one large node, set vm.overcommit_memory to 1, keep transparent huge pages off and swap pressure away, and prove the plan with a load test that forks and resyncs under write load.
Why this question is asked
Sizing is where many Redis outages are born. A node that holds the data comfortably on a quiet day can be killed by the operating system during its nightly snapshot, or take an hour to recover after a failover. Interviewers ask this design question because it shows whether we know everything that lives in a Redis process besides the data, and whether we design for the bad day rather than the average one. In this answer, we will build the memory budget item by item, do the arithmetic for this deployment, choose a shard size, set the operating-system settings, and plan the test that proves it.
1Requirements and Rough Numbers
The deployment holds about 120 GB of data, uses AOF for durability and daily RDB snapshots for backups, has one replica per primary, and takes a steady 30,000 writes per second. Let us assume an average write of about 1 KB including the key and protocol, which gives roughly 30 MB per second of write traffic to replicate and append to the AOF.
Persistence matters for sizing because both BGSAVE and BGREWRITEAOF fork a child process. The child shares memory with the parent through copy-on-write: a page is only duplicated when the parent modifies it while the child is still writing. With 30,000 writes per second spread across the keyspace, a snapshot that takes several minutes can touch a large share of pages, so the extra memory can approach the size of the dataset in the worst case.
2The Memory Budget, Item by Item
Fragmentation comes first: RSS is usually 10 to 30 percent above used_memory, depending on value sizes and churn. Next are client buffers, the input and output buffers for every connection, small normally but able to spike. Then replication: each replica has an output buffer on the primary, and the replication backlog is a ring buffer that lets a replica reconnect after a short break without a full resync. Its default, repl-backlog-size 1 MB, covers only a fraction of a second at 30 MB per second, so we raise it to cover a few minutes, for example 2 to 4 GB per primary for a fleet this busy, or less per shard once we split.
Then copy-on-write during forks, the largest and least predictable item. And finally the operating system itself, page cache for the AOF and RDB files, and any agents on the host. The practical rule that comes out of this is maxmemory at about 60 to 75 percent of RAM when persistence and forks are in play. Without persistence and forks, a higher share, around 80 to 85 percent, is possible.
- Data (maxmemory)about 22 GB, 70 percent of RAM
- Fragmentation10-30 percent of data, about 3 GB
- Buffers and backlogclients, replica output, repl backlog, about 1 GB
- Copy-on-write headroompages duplicated during BGSAVE or AOF rewrite
- OS and page cachekernel, AOF and RDB file cache, agents
5 layers, from the top down. Step through them one at a time.
The data is less than three quarters of what the node must hold on its worst day.
3Choosing the Shard Size
We could put 120 GB on one primary with 192 GB of RAM. It would work on a quiet day and hurt on every bad day. A fork of a 120 GB process copies page tables for a pause that can reach a second or more. A full resync of a new replica means writing and transferring a 120 GB snapshot, which takes tens of minutes, during which the primary holds a growing replica buffer. A restart loads 120 GB of AOF or RDB, which can take most of an hour. And any failure affects all the data at once.
With five or six shards of 20 to 25 GB in Redis Cluster, each of those times shrinks by the same factor: forks pause for tens of milliseconds, resyncs and restarts take minutes, and a failure affects a sixth of the keyspace. The cost is a cluster-aware client and hash tags for multi-key operations. For 30,000 writes per second, a single main thread would cope, but splitting also leaves headroom for growth.
| 1 x 120 GB primary | 6 x 20 GB primaries | |
|---|---|---|
| Fork pause | hundreds of ms to seconds | tens of ms |
| Full resync of a replica | tens of minutes | a few minutes per shard |
| Restart and load | most of an hour | minutes |
| Copy-on-write peak | up to about 120 GB extra | up to about 20 GB per node |
| Blast radius | all data | one sixth of the keys |
4Operating-System Settings That Matter
vm.overcommit_memory should be 1. With the default heuristic mode, the kernel may refuse a fork of a large process because it counts the child's possible memory as if it would all be copied, and BGSAVE then fails with Cannot allocate memory. Transparent huge pages should be off for the Redis process, because with 2 MB pages a single changed byte duplicates 2 MB during copy-on-write instead of 4 KB; Redis 6.2 and later disable them for its own process with disable-thp, on by default.
Swap should not be part of the plan: a swapped Redis page stalls every client, so hosts should have swap disabled or swappiness near zero. And network bandwidth matters for full resyncs: transferring 20 GB at 10 Gbps takes about 16 seconds of full link use, which also delays client traffic, so resyncs should be rare and ideally planned.
5Proving the Plan
Numbers from a whiteboard need a test. We load production-like data into one shard at its target size, run the steady 30,000 writes per second (scaled to the shard), and then trigger the expensive events while the writes continue: BGSAVE, BGREWRITEAOF and a full resync of a fresh replica. For each we record peak RSS on the host, latest_fork_usec from INFO stats, the time the operation took and the time to full recovery.
If peak RSS stays under, say, 85 percent of RAM through all three, the budget holds. If not, we lower maxmemory or use smaller shards. We repeat the test after any major change in data shape or write rate.
6Follow-up questions
What changes if you drop AOF and rely on replicas only?
Without AOF and without RDB on the primary, there are no forks there, so copy-on-write headroom disappears and maxmemory can rise to about 80 to 85 percent of RAM, and there are no fsync stalls. But a full resync of a replica still forks the primary to produce the snapshot, even with diskless sync, and durability now depends on replicas: if a primary and its replica fail together, or a failover loses the last writes, those writes are gone. Many teams keep RDB snapshots on replicas only, which keeps backups without forking the primary.
How big should the replication backlog be?
Big enough to cover the longest replica disconnect we want to survive without a full resync. At 30 MB per second of writes cluster-wide, or about 5 MB per second per shard, a 1 GB backlog per shard covers over three minutes, which handles network blips and quick restarts.
Does Redis Cluster change the maxmemory rule?
No, it applies per node. What changes is that every node is smaller, so fork pauses, copy-on-write peaks and recovery times shrink with it.
7Conclusion
In this answer, we saw that a node must hold far more than its data: fragmentation, client and replication buffers, a backlog sized for minutes of writes, copy-on-write during forks and the operating system. With persistence, maxmemory at about 60 to 75 percent of RAM is a safe rule, and splitting 120 GB into shards of 20 to 25 GB makes forks, resyncs, restarts and failures smaller. vm.overcommit_memory 1, transparent huge pages off and no swap complete the setup, and a load test that forks and resyncs under write load proves it.
Open with
I would start by budgeting beyond the 120 GB of data. Fragmentation is often 10 to 30 percent. There are client buffers, replica output buffers and the replication backlog, whose default of 1 MB is far too small at 30,000 writes per second, so I would size it for a few minutes of writes.
Then, if they want more
The biggest item is copy-on-write: BGSAVE and AOF rewrite fork a child, and under heavy writes the duplicated pages can approach the dataset size. That is why, with persistence, I set maxmemory to about 60 to 75 percent of RAM; without forks I could go higher.
For shard size, I would prefer five or six shards of 20 to 25 GB over one 120 GB node, because forks are short, a full resync or restart takes minutes instead of close to an hour, and a failure hits a smaller slice.
On the operating system, vm.overcommit_memory equals 1 so fork does not fail, transparent huge pages off, which Redis 6.2 and later do for themselves with disable-thp, no swap pressure, and enough network bandwidth for resyncs.
Finally I would prove it: load production-like data, run BGSAVE, BGREWRITEAOF and a full replica sync under write load, and record peak RSS, latest_fork_usec and recovery times.
About this answer
- Last updated
- 13 November 2026
- Versions it names
- Redis 6
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Redis documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "How do you size memory per node, choose the shard size and set maxmemory, and which...": https://scrivio-interview-library.netlify.app/databases/redis-internals/f8cba472f3/