Video in progress
Estimate roughly how much memory a Redis cache for a product catalog needs.
The catalog has 5 million products. One product is about 2 KB as JSON on average. About 80% of traffic goes to about 20% of the products. The cache hit ratio needs to be at least 80%.
Start from the number of unique objects read per day and the size of one object; by the 80/20 rule you cache the hot 20%. Then add Redis's per-key and structure overhead, plus headroom for replicas and growth.
📖 Answer
I'll work through it out loud, with round numbers.
If we cache everything: 5M × 2 KB = 10 GB.
Only the hot part: 20% × 5M = 1M products × 2 KB = 2 GB. That roughly covers the required 80% hit ratio.
Now the Redis overhead. Each key has its own metadata, the key name (product:1234567 — ~15 bytes), the dict table. With small values the overhead is noticeable; at 2 KB it's roughly 10–20%. Say 2 GB × 1.2 ≈ 2.4 GB.
Fragmentation and headroom: you shouldn't give Redis more than 70–75% of the container's memory (fork, buffers). 2.4 GB / 0.7 ≈ 3.5 GB. Rounding up for growth — a 4 GB instance.
If there's a replica, the same amount again.
Two more things:
- Caching the full 10 GB isn't actually expensive. Sometimes "cache everything" is the simplest solution, because you think less about invalidation and misses.
- The number has to be checked later on prod:
used_memoryinINFO memoryandkeyspace_hits / (hits + misses). The estimate is only a starting point.
A compact format instead of JSON (for example, storing only the fields you need) can cut the size 2–3 times — often a cache doesn't need the whole object.
Sign up to mark studied questions and save your progress.