How should caching work in a production app?
Caching is a consistency decision, not just a speed trick.
- Layers: browser/CDN for safe public content → server cache for expensive repeated reads → Redis only when several instances need shared ephemeral data or you have measured hot keys
- Choose TTL and invalidation per data class (cache-aside, write-through); prevent stampedes with locks or request coalescing
- Never cache one tenant's confidential result under a key another tenant can reach
- Never serve stale permissions — a cache must not be the source of truth for authorization or money
- Watch memory, evictions, hit rate and hot keys; and have a plan for Redis being down
Rule: if you can't say how an entry gets invalidated, don't cache it.