Memory & Cache-Sizing Playbook
The formula
Cache size = hot_fraction × total_items × bytes_per_item × (1 + overhead)
Overhead (~25–50%) covers keys, pointers, and fragmentation in Redis/Memcached.
The 80/20 rule
Usually ~20% of items serve ~80% of reads. Cache the hot fraction, not everything — that’s what makes caching cheap and effective.
Worked example
500M items, ~1 KB each, ~20% hot, 30% overhead:
- Working set = 0.20 × 500M × 1 KB = ~100 GB × 1.3 ≈ ~130 GB.
- Gate: >~200–300 GB won’t fit one node ⇒ shard the cache (consistent hashing).
Hit-ratio economics
Effective latency = hit% × cache_latency + miss% × db_latency. With a 95% hit ratio:
0.95×0.5ms + 0.05×10ms ≈ 0.97 ms — but your p99 lands in the 5% miss path, so size the cache to keep that miss path survivable.
Formulas are standard/public-domain engineering math. Approach and reference-table format adapted from the System Design Primer (CC BY 4.0), Jeff Dean’s latency numbers, the DesignGurus capacity-estimation guide, and Little’s Law.
🤖 Don't fully get this? Learn it with Claude
Stuck on Memory & Cache-Sizing Playbook? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.
Build the mental picture, not memorization.
I just read a lesson on **Memory & Cache-Sizing Playbook** (System Design) and want to truly understand it. Explain Memory & Cache-Sizing Playbook from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
Socratic — adapts to where you're stuck.
Teach me **Memory & Cache-Sizing Playbook** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
Active recall exposes what you missed.
Quiz me on **Memory & Cache-Sizing Playbook** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
Intuition + hook + flashcards for long-term memory.
Help me remember **Memory & Cache-Sizing Playbook** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.