Scrivio Interview library
DebuggingIntermediate6 min read · updated 13 November 2026

A user-profile store keeps 30 million hashes of about 12 short fields each in Redis 7.2, using 9 GB. A release adds a free-text bio field, often 100 to 300 characters long, and within a day used_memory reaches 26 GB.

Explain why memory nearly tripled when the data grew only a little, how you would confirm it, and what you would change.

The new bio values are longer than hash-max-listpack-value, 64 bytes by default, so every profile that gets a bio converts from a compact listpack to a hashtable, and each of its 13 fields then costs a dictionary entry and separate allocations instead of a few bytes in one array. I would confirm it with OBJECT ENCODING and MEMORY USAGE on profiles with and without a bio, move the bio into its own string key, and then rewrite the hashes that already converted, because they do not shrink back on their own.

Why this question is asked

This incident is a favourite in interviews because the numbers look impossible: a few hundred bytes of text per user should add a few GB, not 17. The explanation is a Redis internal that most application developers never hear about until it bites them. In this answer, we will recap how small hashes are stored, see exactly why one long field changes the cost of every field, confirm it with real commands, and then go through the fixes and the step that people usually forget.

1A Quick Recap of Hash Encodings

Redis stores a small hash as a listpack: a single byte array with field and value one after another. It uses this form while the hash has at most hash-max-listpack-entries fields (128 by default) and every field and value is at most hash-max-listpack-value bytes (64 by default). A profile with 12 short fields, such as name, city and plan, fits easily and costs about 300 bytes in total.

Once a hash breaks either limit, Redis converts it to a hashtable. In a hashtable every field and every value is its own string allocation, each field needs a dictionary entry, and the table needs bucket slots, so each field costs around 50 to 80 bytes of overhead on top of its data.

2Why One Long Field Changes Everything

The bio is often 100 to 300 characters, well above 64 bytes. The moment a profile receives one, the whole hash converts. It is not only the bio that becomes expensive; all 12 existing fields move from a few bytes each inside the listpack to separate allocations in a dictionary.

Let us put numbers on it. 30 million profiles at 9 GB means about 300 bytes per profile including the key overhead. A converted profile with 13 fields at, say, 70 bytes of overhead per field plus data plus the 200-byte bio comes to roughly 850 to 1,000 bytes. If most active users fill in a bio within a day, 30 million times around 870 bytes is about 26 GB. So the growth is not from the bio text, which adds only about 6 GB in total, but from the change of encoding.

Step throughHow one HSET converts a profile
  1. HSET profile:42 bio <210 bytes>application writes the new field
  2. Value longer than hash-max-listpack-value?
    Yesconvert the whole hashNostay a listpack
  3. Convert to hashtableeach of 13 fields becomes separate allocations
  4. Memory per profileabout 300 bytes -> about 900 bytes

4 steps in order. Play them, or step through them one at a time.

The conversion is triggered by one field but changes the cost of all of them.

3Confirming It on Samples

We do not need to guess. Take two profiles, one with a bio and one without, and compare.

Text
OBJECT ENCODING profile:1001 -- "listpack" (no bio)
MEMORY USAGE profile:1001 -- (integer) 296
OBJECT ENCODING profile:1002 -- "hashtable" (has a bio)
MEMORY USAGE profile:1002 SAMPLES 0 -- (integer) 1104
CONFIG GET hash-max-listpack-value -- 1) "hash-max-listpack-value" 2) "64"

That pair shows the mechanism. To see how much of the keyspace is affected, run redis-cli --memkeys against a replica, or better, take an RDB file and analyse it offline with an RDB analysis tool, which reports the encoding mix and sizes by key pattern without touching production. If the share of hashtable-encoded profiles roughly matches the share of users with a bio, the case is closed.

4Fix 1: Keep Long Text Out of the Hash

The best fix is to store the bio separately, in its own string key such as profile:42:bio. The hot, small fields stay in a listpack hash, and the bio costs its own length plus one key's overhead. If bios are large and read rarely, they can be compressed in the application before writing. Reading a profile page that needs both is one pipelined round trip, or an HGETALL and a GET in the same batch.

This also follows a good general rule: keep short, frequently read attributes together, and put large, rarely read blobs in their own keys.

5Fix 2: Raise the Value Limit, Carefully

Alternatively we can raise hash-max-listpack-value to, say, 320 bytes so profiles with a bio stay listpacks. It works, but it has a cost: listpack lookups scan the array, so a 4 KB listpack makes every HGET and HSET on that hash slower, and the release could also bring the next field that is longer still. If we raise the value limit, we should keep the entry count low and benchmark HGET and HSET latency at the new size before rolling it out.

6Getting the Memory Back

Whatever we choose, the profiles that already converted stay hashtables. Redis never converts a hash back when fields shrink or disappear. So after the fix we must rewrite the affected hashes: a job that scans profile:* keys, and for each one that is a hashtable, moves the bio to its new key and writes the hash fresh (for example read it with HGETALL, delete it and write it back in a MULTI/EXEC, or DUMP and RESTORE with REPLACE). New hashes are created as listpacks again. Run the job slowly, in batches, against the primary while watching latency. Then check used_memory falling back towards 9 GB plus the bios.

7Follow-up questions

How could a review have caught this before the release?

By making key design part of the review for any change to a Redis data shape: what is the largest value a field can hold, and does it cross an encoding limit? A test that writes a realistic profile and asserts OBJECT ENCODING is listpack, and a staging load of a few hundred thousand realistic profiles with INFO memory compared before and after, would both have shown the jump.

Would compressing the bio inside the hash help?

Only if it brings every value under 64 bytes, which is unlikely for 300 characters. Any value over the limit still converts the hash, so compression alone does not fix the encoding problem.

Could a restart fix it?

A restart reloads the data and creates each hash fresh, but a hash that still contains the long bio would convert again during loading. A reload only helps once the long values are gone or the limit is raised.

8Conclusion

In this answer, we saw that a value longer than hash-max-listpack-value converts the whole hash from a listpack to a hashtable, which multiplies the cost of every field and explains memory nearly tripling. We confirmed it with OBJECT ENCODING, MEMORY USAGE and an offline RDB analysis, fixed it by moving the bio into its own key or carefully raising the limit, and remembered to rewrite the converted hashes, because they never shrink back on their own.

What to say in the interviewAbout 80 seconds aloud

Open with

The bio values are 100 to 300 characters, and hash-max-listpack-value is 64 bytes by default, so the first HSET of a bio converts that profile from a listpack to a hashtable.

Then, if they want more

In a listpack the 12 fields cost a few bytes each in one array; in a hashtable each field gets a dictionary entry, separate string allocations and bucket space, so the profile goes from around 300 bytes to around 900. Times 30 million, that is the jump to 26 GB, much more than the bio text itself.

To confirm, I compare OBJECT ENCODING and MEMORY USAGE on a profile with and without a bio, and look at the encoding mix across the keyspace with redis-cli --memkeys on a replica or an offline RDB analysis.

My preferred fix is to keep the long text out of the hash, in a separate string key, compressed if it helps, so the hot small fields stay compact. The alternative is raising hash-max-listpack-value after benchmarking, since listpack lookups are linear, keeping the entry count low.

Either way, the hashes that already converted stay hashtables, so I would run a careful job to rewrite them and get the memory back.

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 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 "Explain why memory nearly tripled when the data grew only a little, how you would...": https://scrivio-interview-library.netlify.app/databases/redis-internals/127b142553/