Layer 3: Application cache (Redis / Memcached)
Ok this is the one everyone knows. The one people mean when they say "let's add caching."
But honestly? Most teams use it wrong. They throw Redis in front of their database and call it a day. Then wonder why it doesn't help much.
Let me break down how to actually think about it.
What it does:
Your app stores frequently-accessed data in an in-memory store (Redis, Memcached). Reading from memory is ~1-5ms. Reading from a database is 20-100ms. That's a 10-50x speedup.
The pattern that works (cache-aside):
1. App gets a request
2. Check Redis: "do I have this?"
3. YES โ return it (cache hit, 1-2ms)
4. NO โ query the database, store result in Redis, return it
5. Next request for same data โ step 3 (fast path)
Simple. Effective. This is what 90% of teams should start with.
What to put in it:
- Results of expensive queries (aggregations, joins across big tables)
- Session data
- Frequently accessed objects (user profiles, product details, configs)
- Computed results (leaderboards, recommendation lists, feed rankings)
- Rate limiting counters
What NOT to put in it:
- Data that changes every request (you'll invalidate more than you serve)
- Very large objects (eating up memory for stuff that's rarely accessed)
- Data where staleness = real money lost (use the database directly)
Redis vs Memcached:
People ask this all the time. Simple answer:
Memcached: pure key-value. Multi-threaded. Dead simple. If all you need is "store this string, get this string," it's faster and lighter.
Redis: key-value PLUS data structures. Sorted sets, lists, pub/sub, Lua scripting. If you need a leaderboard, a rate limiter, a queue, or anything beyond simple get/set, Redis.
Most teams pick Redis because it does everything. That's fine. But if you're running a massive session cache and literally just need get/set at high throughput, Memcached is worth considering.
The mistake I see most often:
Teams cache everything with a 1 hour TTL and never think about invalidation. Then users see stale data and they blame caching itself.
Caching isn't the problem. Lazy TTLs are the problem. More on invalidation in tomorrow's thread (Day 4).