Scrivio Interview library
ConceptFoundations6 min read · updated 13 November 2026

A team plans to keep login sessions for 50 million active users in Redis, about 1 KB of data each, and asks for one 64 GB Redis instance with a replica.

Estimate the memory really needed and say whether one 64 GB instance is enough.

The raw data is 50 million times 1 KB, about 50 GB, but Redis needs more than that: per-key overhead of roughly 50 to 100 bytes adds a few GB, allocator fragmentation adds 10 to 30 percent, and a fork for snapshots or replica sync can need extra memory through copy-on-write. Keeping used memory under about 75 percent for headroom, the real need is around 80 to 100 GB, so one 64 GB instance is not enough. The options are smaller sessions, a larger instance, or sharding across several primaries, each with a replica.

Why this question is asked

Memory sizing is a classic estimate because the naive answer, 'number of items times item size', is almost always too small, and the system fails in an unpleasant way when it runs out. For Redis, running out of memory means evicted sessions and logged-out users, or rejected writes, depending on the eviction policy. Interviewers use this question to see whether we know where the hidden memory goes. In this answer, we will compute the raw size, add Redis's per-key overhead, fragmentation and fork cost, apply headroom, and decide what to do instead of a single 64 GB instance.

1The Raw Data

We start with the simple multiplication: 50 million sessions times 1 KB of data each is 50 million KB, which is 50 GB in decimal units, or about 47.7 GiB. It is already uncomfortably close to 64 GB before we have counted anything Redis adds. That alone is a warning sign, but the more useful exercise is to see how much more Redis actually needs.

2Per-Key Overhead Inside Redis

Each session is stored as a key, such as session:3f9a... with a 32-character id, and a value. Redis does not store just those bytes. It keeps an entry in its main hash table that points to the key and the value, the key itself as a string with a small header, a value object with its own header, and, because sessions expire, a second entry in the table of keys with a time to live. Each allocation is also rounded up to the allocator's size classes.

Together these typically add around 50 to 100 bytes per key, on top of the key name itself. For 50 million keys, 75 bytes of overhead plus a 40-byte key name is about 115 bytes, or nearly 6 GB. If the session is stored as a hash with many small fields instead of one serialized string, the overhead can be higher or lower depending on the encoding, which is a reason to measure rather than guess.

3Fragmentation and the Cost of Forking

Redis allocates memory through jemalloc, an allocator that groups allocations into size classes. As sessions are created, updated and expired, freed memory is not always reusable for new allocations of different sizes, so the process holds more memory than its data needs. INFO memory reports this as mem_fragmentation_ratio; values of 1.1 to 1.3, meaning 10 to 30 percent extra, are common for workloads with lots of churn, such as sessions.

The second hidden cost comes from persistence and replication. To write an RDB snapshot, or to send a full copy to a replica during initial sync, Redis forks a child process. The child shares the parent's memory pages, and the operating system copies a page only when the parent modifies it, a technique called copy-on-write. Under a steady stream of session writes, a noticeable fraction of pages are copied during the minutes the fork runs, so the machine needs spare memory for those copies. Replicas also need output buffers on the primary while they sync.

4Adding It Up With Headroom

Now we put the pieces together and add headroom for growth and peaks. A common rule is to keep used memory well below the instance size, often under 75 percent, so that a fork, a traffic spike or a burst of new sessions does not push the machine over.

Java
raw sessions = 50,000,000 x 1 KB = 50 GB
key names + overhead = 50,000,000 x ~115 bytes = ~6 GB
subtotal = 56 GB
fragmentation 10-30% = 56 GB x 1.1 to 1.3 = 62 to 73 GB
headroom (use <= 75%) = 62 to 73 GB / 0.75 = 83 to 97 GB
conclusion = about 80 to 100 GB of instance memory; 64 GB is not enough
Where the memory goes
PartEstimateNotes
Session values50 GB50 million x 1 KB
Keys and Redis overheadabout 6 GBHash entry, objects, expiry entry
Fragmentation6 to 17 GBmem_fragmentation_ratio 1.1 to 1.3
Fork and bufferscovered by headroomCopy-on-write during snapshot or sync
Headroom for growthabout 25 percentKeep used memory under 75 percent
Total instance memory80 to 100 GBOne 64 GB instance falls short

5What to Do Instead

There are three ways forward, and they combine well. The first is to make sessions smaller. A 1 KB session often holds things that do not belong there, such as full user profiles or permission lists that can be loaded on demand. Trimming to 300 bytes and compressing the serialized value cuts the need by more than half. Shorter session lifetimes also reduce the number of live keys.

The second is a larger instance, for example 128 GB, with a replica of the same size. That is the simplest change, but it keeps everything on one primary, so a failover affects every session and a fork of a 70 GB process takes longer.

The third is sharding: Redis Cluster splits the key space into 16,384 hash slots spread across several primaries, each with its own replica. Three primaries of 64 GB each would hold about 25 GB of data apiece, leaving plenty of room for forks and growth, and each one can be scaled independently. Clients need to be cluster-aware, which Lettuce and Jedis both are. For a session store at this size, sharding plus trimming the session payload is usually the best long-term answer.

6Follow-up questions

How would you measure the real per-session size before deciding?

Load a realistic sample, say one million sessions copied or synthesised from production data, into a test Redis instance, and compare used_memory in INFO memory before and after; dividing the difference by one million gives the true per-session cost including overhead. MEMORY USAGE on individual keys shows the cost of a single session, and redis-cli --memkeys or --bigkeys finds unusually large ones. Watching mem_fragmentation_ratio after a period of realistic churn gives the fragmentation factor.

Does the replica need the same memory?

Yes. A replica holds a full copy of the data and must be able to take over as primary, so it needs the same size, and it will also fork if it writes snapshots.

Which eviction policy should a session store use?

Usually volatile-ttl or volatile-lru, so that only keys with an expiry are evicted, or noeviction if losing sessions silently is worse than failing writes; either way, alerts should fire well before maxmemory is reached.

7Conclusion

In this answer, we saw that 50 million 1 KB sessions are 50 GB of raw data but need much more in Redis: about 6 GB of key and per-key overhead, 10 to 30 percent fragmentation, and spare memory for copy-on-write during forks. With headroom to keep usage under 75 percent, the need is about 80 to 100 GB, so one 64 GB instance is not enough. Trimming sessions, a larger instance, or a Redis Cluster with several primaries and replicas are the ways forward.

What to say in the interviewAbout 90 seconds aloud

Open with

The raw data is fifty million times one kilobyte, about fifty gigabytes, which is already close to sixty-four. But Redis needs more than the raw data. Each key carries overhead for the main hash table entry, the key string, the value object and the entry in the expiry table, typically fifty to a hundred bytes per key, so with the key names that is another five or six gigabytes.

Then, if they want more

Then jemalloc fragmentation commonly adds ten to thirty percent for a workload with a lot of churn like sessions. On top of that, when Redis forks to write a snapshot or to sync a replica, copy-on-write duplicates pages that change during the fork, so we need spare memory.

If I keep used memory under about seventy-five percent, the real requirement is roughly eighty to a hundred gigabytes, so one sixty-four gigabyte instance is not enough.

I would first measure the real per-session cost by loading a million realistic sessions and comparing used_memory, and look at whether the session can be trimmed, because a kilobyte often includes data that can be loaded on demand.

Then I would either take a larger instance or, better for growth, use Redis Cluster with three primaries, each with a replica, so each holds around twenty-five gigabytes with comfortable headroom.

About this answer

Last updated
13 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
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 "Estimate the memory really needed and say whether one 64 GB instance is enough.": https://scrivio-interview-library.netlify.app/architecture/sd-fundamentals/6fbae14ea5/