Video in progress

In prod, Redis suddenly starts returning `OOM command not allowed when used memory > 'maxmemory'` and order creation stops working. What do you do during the incident and after it?

First I stop the bleeding: quickly find who is using the memory and free a safe part of it, or temporarily raise maxmemory. Then I find the cause (keys without a TTL, a big key, grown buffers), and to prevent a repeat I separate the cache from critical state and set an early memory alert and a key budget.

📖 Answer

This error means the noeviction policy and full memory. The important thing is that Redis still answers reads and only rejects writes.

During the incident (the first 15 minutes):

  1. Determine the impact: which services can't write, and why order creation depends on a write to Redis (idempotency? a lock? the cache?).
  2. What is using the memory:
INFO memory          -- used_memory, used_memory_dataset, mem_fragmentation_ratio
INFO clients         -- clients with large output buffers
MEMORY DOCTOR
redis-cli --bigkeys  -- on a replica

Sometimes the memory isn't taken by the dataset but by the output buffer of a slow Pub/Sub subscriber or a client running MONITOR; CLIENT KILL frees it right away.

  1. Quick relief (starting with the least risky):
  • on managed/VM, if possible, temporarily raise CONFIG SET maxmemory (if physical memory allows);
  • delete a clearly unneeded prefix (for example, an old cache) with SCAN + UNLINK;
  • if the instance also holds a cache, clear those cache keys.

What must not be deleted: idempotency or lock keys, because deleting them can lead to creating a payment twice.

After the incident (the postmortem):

  • The root cause is usually one of these: a new feature started writing without a TTL; traffic grew and the dataset went past maxmemory; Streams growing without MAXLEN; a big key.
  • Why does order creation depend so hard on Redis? Probably a cache write error is failing the request, and cache errors should have been swallowed (CacheErrorHandler).
  • The cache and critical state were on one instance, and they should be separated: the cache on its own with allkeys-lru, and the critical state on its own with noeviction.

Prevention:

  • a warning at used_memory / maxmemory > 75%, and a page at > 85%;
  • a dashboard of memory growth by prefix, and a daily report;
  • a code review rule, and banning or warning on writes without a TTL in the platform library;
  • a load test and a capacity plan: a forecast of "how many days until it's full" from the dataset's growth rate.

In the postmortem I give one question its own answer: which metric showed this 2 weeks ago, and why did nobody look at it?