Cache-aside
A pattern that loads data into the cache from the data store on demand.
Structure and behavior
Follow the arrows step by step.
On a cache miss, read the source and populate the cache. Define expiry (TTL), refresh, and invalidation policies.
Expected benefits
Reduces latency and contention in the source data store and improves concurrent request handling.
Trade-offs
Dual writes to cache and data store can diverge and may require retries and reconciliation logic.
Not a fit if strong consistency is required, writes are frequently followed by immediate reads, or cache misses are costly.
Operations and adoption guide
Synthesis, distinct from items backed by source excerpts. Validate before applying in production.
When to use
Use for read-heavy data with many repeated lookups and tolerance for brief staleness, such as product catalogs, user profiles, or API responses.
Scenario
A large e-commerce or supply-chain platform serves 100 million reads and 50,000 writes per day. It targets P95 product and inventory lookup latency below 100 ms and at least 70% lower source DB load. On a miss the application reads the DB and populates Redis with a TTL, then invalidates cached stock levels on inventory changes. Up to five minutes of stale price or stock display is acceptable, but checkout uses authoritative DB values.
Placement principles
- Keep the cache-aside lookup logic with the application and put shared Redis between it and the source database
- Place static public data at the edge CDN and user or domain data in the application cache
- Keep the source DB authoritative and manage cache TTLs and invalidation
- In Kubernetes, separate the app Deployment, Redis StatefulSet or Operator or managed cache, and CloudNativePG or managed RDB
- Isolate hot keys and large keys with a separate cache tier or sharding.
On premises
Run Redis HA with Sentinel or Cluster and separate latency paths and fault domains among the app, cache, and DB. Tune connection pools, timeouts, and circuit breakers for miss storms, and standardize invalidation, retries, and monitoring.
Cloud
Use managed ElastiCache, MemoryDB, or Azure Cache for Redis across multiple availability zones. Apply least privilege via VPC, security groups, and IAM. Verify client connections, retry and timeout settings even with managed services, and test DB fallback and capacity protection before release.
Kubernetes
Run the stateless app with a Deployment, HPA, PDB, and readiness probes. Separate Redis into an Operator, StatefulSet, or external managed cache. Configure connections with ConfigMaps and Secrets, restrict app, DB and cache access with NetworkPolicy, and protect the DB with timeouts, breakers, and rate limits.
Incident response
Typical incidents include cache node failure, mass evictions, hot keys, stampedes, stale data from missed invalidations, and divergence after dual cache/DB writes. Check hit rate, evictions, latency, errors, and DB QPS. Treat failed cache connections as misses after a timeout and fall back to the DB, protecting it with limits and breakers. If necessary clear the cache, temporarily shorten TTLs, warm it gradually, and perform a postmortem.
Evidence by criterion (14 total)
Evidence availability at the time of research. Assess source accuracy and currency separately.
Definition and overviewEvidence available
A pattern that loads data into the cache from the data store on demand.
Load data on demand into a cache from a data store.Problem addressedEvidence available
Reduces P95 latency and load on the database when read-heavy workloads repeatedly request the same records.
Primary databases optimized for durability pay the full cost of a disk-based lookup on every request; as traffic grows, P95 latency degradesKey components and resourcesEvidence available
The application manages access to the cache and the source data store.
Cache-Aside uses a cache alongside the source data store, with the application managing access to both.Data and asset placementEvidence available
Put an edge CDN ahead of the read-optimized web tier, the application cache-aside layer next, and the database behind it.
A read-optimized web tier fronts the database with an edge CDN and application cache-aside layer.Typical use casesEvidence available
Useful for workloads with repeated reads, such as product catalogs, user profiles, and API responses.
Read-heavy workloads (product catalogs, user profiles, API responses) hit the same records thousands of times between updates.Example scenarioEvidence available
Example: a web architecture optimized for reads in a supply-chain and planning platform.
Design a Kubernetes architecture for a Supply Chain & Planning platform using the Cache-Aside Read-Heavy Web pattern.When to avoid and caveatsEvidence available
Not a fit if strong consistency is required, writes are frequently followed by immediate reads, or cache misses are costly.
You need strong consistency between cache and databaseOn premises: development, deployment, and operationsUnverified
No primary-source evidence was recorded. This does not imply that the pattern is unsuitable.
Cloud: development, deployment, and operationsEvidence available
Misconfigured clients can cause recurring managed cloud cache outages. Validate settings, retries, and timeouts.
a small number of client-side misconfigurations in how applications connected to ElastiCache were causing repeated disruptions.Kubernetes: development, deployment, and operationsEvidence available
In Kubernetes, run the cache-aside application as a Deployment and combine it with Redis, a database, and Ingress or a CDN.
Design a Kubernetes architecture for a Supply Chain & Planning platform using the Cache-Aside Read-Heavy Web pattern.Incident responseEvidence available
If the Redis connection fails, fall back transparently to the database instead of returning a user-facing error.
If the Redis connection fails, the application must transparently fall back to the database instead of returning an error to the user.BenefitsEvidence available
Reduces latency and contention in the source data store and improves concurrent request handling.
Caching reduces the latency and contention that are associated with handling large volumes of concurrent requests in the original data store.Drawbacks and trade-offsEvidence available
Dual writes to cache and data store can diverge and may require retries and reconciliation logic.
Imagine that you’ve successfully updated the cache but the datastore fails to update. The code needs to implement retries.Representative tools and technologiesEvidence available
Redis is a representative in-memory cache.
Redis In-memory cacheAdditional references (23)
- Cache-Aside Pattern - Azure Architecture Center | Microsoft Learn ↗
- Redis cache-aside ↗
- Caching Best Practices | Amazon Web Services ↗
- How to use Redis for Query Caching ↗
- Cache-Aside ↗
- Cache-Aside Pattern (Lazy Loading) - Redis Patterns ↗
- A Hitchhiker's Guide to Caching Patterns ↗
- The Architect's Guide to Common Caching Patterns ↗
- Caching Guidance - Azure Architecture Center ↗
- Deploy Amazon EKS clusters across cloud and on-premises environments - Amazon EKS ↗
- How to Run Kubernetes Across On-Premises and Public Cloud: Four Hybrid Architecture Models and the Seven Layers to Standardize ↗
- Supply Chain & Planning — Cache-Aside Read-Heavy Web (Kubernetes) — Architecture Diagram Template ↗
- Reference Architecture: GKE Enterprise hybrid environment - part 2 - Dec '24 - Google Docs ↗
- Deploy Containerized Apps with AKS Hybrid and Edge by Using GitOps - Azure Architecture Center | Microsoft Learn ↗
- Understanding the Cache-Aside Pattern: A Practical Guide | by Mallikarjuna Mallesha ↗
- Kubernetes Deployment Options for On-Prem Clusters ↗
- How Intuit and AWS systematically improved resiliency on ElastiCache using AWS Fault Injection Service | AWS Database Blog ↗
- When the cache fails: fail-open, fail-closed and the cascade | ShardCraft ↗
- Google SRE - Cascading Failures: Reducing System Outage ↗
- Implementing the Cache-Aside Pattern Correctly ↗
- Cache-Aside | Engineer Atlas ↗
- Design a distributed cache · Stanley Jacob ↗
- Cache Invalidation: TTLs, Write Paths, and the Thundering Herd | Scixa ↗