Redis › Caching Patterns

How do you decide which caching pattern, cache aside, write through, or write behind, is right for a specific application feature?

Intermediate

Answer

You consider how tolerant the feature is to slightly stale data, how critical it is that a write is never lost, and how much read versus write traffic the feature experiences, generally choosing cache aside for read heavy data that can tolerate small delays before being cached, write through when consistency matters most, and write behind when write speed is the top priority and some risk of data loss is acceptable.
-- Read heavy, tolerant of staleness: cache aside
-- Consistency critical: write through
-- Write speed critical, some risk acceptable: write behind
Real-world example A team building a product catalog chooses cache aside since catalog data changes infrequently and can tolerate being slightly out of date, while choosing write through for account balance data where consistency is critical.

Common follow-ups: Can different caching patterns be mixed within the same application for different types of data?;How do you measure whether a chosen caching pattern is actually working well in production?