Cache That Added Latency
We added Redis cache to speed things up. It added 50ms latency.
What we cached:
- User profile (changes every request)
- Shopping cart (user-specific, volatile)
- Real-time inventory counts
The problem:
- Cache hit rate: 3%
- 97% of requests: cache miss + DB query
- Plus network round-trip to Redis: 2ms
- Plus serialization/deserialization: 5ms
- Net result: slower than no cache
What we should have cached:
- Product catalog (read-heavy, rarely changes)
- Category tree (static)
- Feature flags (global, rarely changes)
- Computed aggregations (expensive to calculate)
Cache math:
Benefit = (hit_rate × db_latency) - cache_overhead
If benefit < 0, cache is hurting you
Fixed version:
- Removed volatile data from cache
- Added static content with long TTL
- Hit rate: 3% → 85%
- P50 latency: 150ms → 40ms
Lesson: Cache read-heavy, rarely-changing data. Not write-heavy, volatile data.