Scrivio Interview library
ScenarioAdvanced7 min read · updated 13 November 2026

A Redis Stream buffers document-conversion jobs between an upload service and workers. A storage outage stops the workers, the stream grows by 2 million jobs an hour, and Redis will hit maxmemory in about three hours.

What do you do now, and how would you redesign the system so a long outage does not threaten Redis or lose jobs?

Right now we decide what happens at maxmemory before Redis decides for us: with an eviction policy the whole stream key can be evicted, and with noeviction XADD starts failing. We apply backpressure at the upload service, buy time with more memory, and spill low-priority jobs to durable storage. Longer term we keep payloads outside Redis, cap the stream only where old jobs are disposable, size Redis for the longest outage we plan to survive, or move this buffer to a disk-based log such as Kafka.

Why this question is asked

An in-memory buffer has a hard ceiling, and an outage downstream is exactly when we reach it. This scenario is common: the storage system the workers need goes down, producers keep going, and a stream that normally holds a few thousand entries grows by millions. Interviewers ask it to see whether we stay calm, understand what Redis does when memory runs out, and can turn an incident into a better design. In this answer, we will first understand the clock we are racing, then decide what happens at the limit, apply backpressure and buy time, and finally redesign so that a long outage costs a delay rather than data.

1Understanding the Clock We Are Racing

The overview gives us the rate: 2 million jobs an hour, and about three hours of headroom. If an average entry, with its fields and the stream's internal overhead, takes around 1 KB, that is roughly 2 GB of new memory an hour, so we have about 6 GB left. The first thing to do is confirm these numbers rather than trust them: INFO memory for used_memory and maxmemory, XLEN for the length and its growth per minute, and MEMORY USAGE on the stream key with a sample count for its size.

Two other facts shape every decision. A stream is one key, so it lives on one shard even in Redis Cluster; adding nodes does not help this key. And no job is processed while storage is down, so whatever we do, the backlog only shrinks after the outage ends.

Text
INFO memory
# used_memory_human:25.80G
# maxmemory_human:32.00G
# maxmemory_policy:allkeys-lru <- the dangerous one, see below
XLEN conversions # (integer) 4120000
MEMORY USAGE conversions SAMPLES 1000 # (integer) 4300000000 (about 4.3 GB)

These sample values show what we look for. The policy line matters most, because it decides how the next three hours end.

2Deciding What Happens at maxmemory

When Redis reaches maxmemory, it follows maxmemory-policy. With an allkeys policy such as allkeys-lru, Redis frees memory by evicting keys, and the stream may be chosen as a victim. Evicting a stream does not trim its oldest entries; it deletes the whole key, so every queued job and the consumer groups' state disappear at once. With a volatile policy, only keys with a TTL are candidates, so the stream survives unless it has one. With noeviction, Redis refuses write commands that need memory: XADD fails with an OOM error, and the producer finds out immediately.

For a job buffer, a loud failure is better than a silent loss, so in most cases we switch to noeviction right now with CONFIG SET maxmemory-policy noeviction, and make sure the upload service treats the XADD error as 'try later' rather than crashing. If this Redis also serves a cache that relies on eviction, that is a sign the two workloads should not share an instance, which we will fix in the redesign.

What happens at the memory limit
PolicyWhat Redis doesEffect on the job stream
allkeys-lru / allkeys-lfuevicts any keystream can vanish with every job
volatile-lru / volatile-ttlevicts keys with a TTLstream survives if it has no TTL
noevictionrejects writes needing memoryXADD fails loudly, jobs kept

3Backpressure and Buying Time

Backpressure means slowing the producer down to match what the system can absorb. The upload service checks XLEN (cached for a second or two, so it does not add load) and, above a threshold such as 5 million entries, answers new uploads with HTTP 503 and a Retry-After header, or accepts the upload but marks the conversion as deferred. Non-critical producers, such as nightly batch re-conversions, are paused entirely.

In parallel, we buy time. A managed Redis can often be scaled to a larger node, and a self-managed one can get more maxmemory if the host has headroom. We also spill low-priority jobs to durable storage: a small job reads entries from the stream, writes them to a database table or object storage as files, and deletes them from the stream with XDEL or by trimming. That converts Redis memory into cheap disk, and we replay those jobs after the outage.

When storage comes back, replay must not stampede it. We feed the spilled jobs back at a controlled rate, for example a few thousand per minute, while watching the conversion latency and the storage error rate, and we raise the rate only while both stay healthy.

4Redesign: Keep the Payload Out of the Stream

Many conversion jobs carry a lot in the entry: file metadata, options, sometimes even small files. If the stream holds only a reference, such as a job id and an object-storage key of 100 bytes, the same 3 hours of headroom becomes 30 hours. The real payload lives in S3 or the database, which are built for volume.

We also cap the stream, but only where old jobs are disposable. XADD conversions MAXLEN ~ 10000000 * job <id> trims old entries as new ones arrive, and MINID trims everything older than a given id, which works like a time cutoff because ids start with a millisecond timestamp. The tilde allows Redis to trim in whole internal nodes, which is much cheaper. Trimming deletes unprocessed jobs, so for document conversions that customers are waiting for, a cap is a safety valve against an outage killing Redis, not a normal operating limit, and it must be paired with spilling to storage.

Finally we size Redis on purpose: decide the longest outage we promise to absorb, say four hours, multiply by the peak rate and the per-entry size, and add headroom. The job stream should live in its own Redis with noeviction and persistence, not alongside a cache.

5When an In-Memory Stream Is the Wrong Tool

If jobs must survive long outages and be replayable, a log-based broker that keeps data on disk fits better. Kafka stores messages on disk with retention measured in days, a backlog of 50 million jobs is ordinary for it, and consumers simply resume from their offsets when storage returns. The cost is operating Kafka, or paying for a managed service, and a little more latency per job.

A reasonable outcome is a split: Redis Streams for short-lived, high-rate work where a backlog of minutes is normal, and Kafka (or a managed queue) for jobs that customers are waiting for and must not be lost.

Step throughRedesigned conversion pipeline
  1. Upload servicewrites the file to S3, rejects with 503 when the backlog is too high
  2. Job logKafka topic or Redis stream holding only job id + S3 key
  3. Workersconsume, convert, acknowledge; claim loop for dead workers
  4. Spill and replaymoves jobs to durable storage during outages, replays at a set rate
  5. StorageS3 and the database keep payloads and results

5 layers, from the top down. Step through them one at a time.

6Follow-up questions

How do you replay the spilled jobs without overwhelming the workers on recovery?

We replay at a controlled rate rather than all at once. A replay job reads spilled jobs in order and writes them back to the stream, a few thousand per minute to start, while watching the workers' error rate and the storage service's latency. If both stay healthy we raise the rate step by step; if errors climb we pause. New uploads keep priority, so customers waiting now are not stuck behind hours of old work, and every handler is idempotent in case a job was both spilled and partly processed.

Would adding more shards to the Redis Cluster help?

Not for this key. A stream is a single key, and a key lives in one hash slot on one shard, so more shards do not give it more memory. Splitting the stream into several streams by a hash of the job id would spread the memory, but it changes the consumers and does not remove the basic limit of an in-memory buffer.

Why not let eviction run with volatile-lru and give cache keys a TTL?

It can work if every cache key has a TTL and the stream never does, but it is fragile: one cache key written without a TTL, or a configuration change, and the protection is gone. A job buffer and a cache have opposite needs, so separate instances are the safer design.

7Conclusion

In this answer, we treated the growing stream as a clock and checked the real numbers first. We decided the outcome at maxmemory ourselves, because eviction can delete the whole stream while noeviction makes XADD fail loudly. We applied backpressure at the upload service, bought time with more memory and by spilling low-priority jobs to durable storage, and planned a gradual replay. For the redesign we keep payloads out of the stream, cap it only where jobs are disposable, size Redis for a chosen outage length, and move must-not-lose jobs to a disk-based log such as Kafka.

What to say in the interviewAbout 80 seconds aloud

Open with

First I would check the numbers myself, used memory against maxmemory, XLEN growth and the stream's MEMORY USAGE, and above all the maxmemory policy. With an allkeys eviction policy the stream key itself can be evicted, and that deletes every job at once, while with noeviction XADD just starts failing.

Then, if they want more

For a job buffer I want the loud failure, so I would switch to noeviction and make sure the upload service handles the error. Then backpressure: when XLEN passes a threshold the upload service returns 503 with Retry-After or defers the conversion, and non-critical producers pause.

To buy time I would scale the node if possible and spill low-priority jobs to the database or object storage, then replay them gradually once storage is back, watching error rates. For the redesign, the stream should hold references, not payloads, so the same memory covers ten times the outage.

I would cap the stream with MAXLEN or MINID only where old jobs are disposable, put the job buffer on its own Redis with noeviction and persistence, and size it for the longest outage we commit to. And if these jobs must survive long outages and be replayable, I would move them to Kafka, which keeps the backlog on disk.

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 "What do you do now, and how would you redesign the system so a long outage does not...": https://scrivio-interview-library.netlify.app/databases/redis-patterns/4bcbc54535/