Reducing Database Load with ElastiCache Caching Strategies
This lesson explains how ElastiCache provides managed in-memory caches that reduce database load and latency, and the strategies for using them.
Learning outcomes
After completing this lesson, you will be able to:
- Choose between the Valkey, Redis OSS and Memcached engines.
- Distinguish lazy loading from write-through.
- Identify the caching service at each layer.
Engines
ElastiCache offers several engines. Valkey and Redis OSS are feature-rich: they replicate to replicas in other Availability Zones with automatic failover, persist data with snapshots, shard data in cluster mode, and provide data structures such as sorted sets, as well as publish-subscribe messaging and geospatial queries. They are the answer when the cache must stay available or needs rich data types. Memcached is a simple, multi-threaded key-value cache with no replication or persistence, for the simplest caching needs.
ElastiCache Serverless removes node selection and scales automatically, for the least operational effort. The following table summarises the options.
| Engine | Features | Choose for |
|---|---|---|
| Valkey / Redis OSS | Replication, Multi-AZ failover, persistence, backups, cluster-mode sharding, sorted sets, pub/sub, geospatial | High availability and rich data types |
| Memcached | Simple multi-threaded key-value, sharding; no replication or persistence | The simplest cache |
| ElastiCache Serverless | Scales automatically, no nodes | Low operational effort |
Uses: query caching, session stores for stateless web tiers, leaderboards, rate limiting, pub/sub, real-time analytics.
Caching strategies
The two main caching strategies differ in when data enters the cache. With lazy loading, also called cache-aside, the application reads the cache first and, on a miss, reads the database and writes the result to the cache. Only data that is actually requested is cached, but each miss adds latency, and cached data can become stale when the database changes.
With write-through, the application updates the cache every time it writes to the database, so cached data is always current, but the cache fills with data that may never be read. The following table summarises the two strategies.
| Strategy | How | Trade-off |
|---|---|---|
| Lazy loading (cache-aside) | Read cache; on a miss, read the DB and populate | Only requested data cached; misses add latency; data can go stale |
| Write-through | Write to the cache whenever writing to the DB | Always current; caches data that may never be read |
Combine either with TTLs. Unlike DAX, ElastiCache needs application code changes.
The following diagram compares the steps of the two strategies.

Lazy loading or write-through?
Caching at every layer
Caching can be applied at several layers of an application. The following table identifies the service used at each layer.
| Layer | Service |
|---|---|
| Edge | CloudFront |
| API responses | API Gateway caching |
| Application data | ElastiCache |
| DynamoDB reads | DAX |
The closer to the user, the bigger the latency win. ElastiCache runs in your VPC behind security groups; Valkey and Redis OSS support encryption in transit and at rest, plus AUTH or IAM.
The following diagram arranges the layers from the user to the data.

Caching at every layer
Taking load off a database
A product catalogue database runs at 90% CPU, almost all from repeated reads of the same popular products.
| Option | Effect |
|---|---|
| Larger database instance | More cost; the same repeated work |
| Read replicas | Spreads reads, still hits disk-based databases |
| ElastiCache with lazy loading and a 5-minute TTL | Popular products served from memory; most reads never reach the database |
Caching is the most effective answer when the same data is read repeatedly. Valkey or Redis OSS suits this case because it supports replication and Multi-AZ failover; Memcached would be chosen only for a simple, multi-threaded cache where losing data on a node failure is acceptable.
Which engine should be chosen when the cache needs replication, persistence and automatic failover?
Show answer
Valkey or Redis OSS. Memcached is a simple, multithreaded cache without replication or persistence.
Exam Tips
Remember for the exam
- For a highly available cache with failover and persistence, use ElastiCache for Valkey or Redis OSS with Multi-AZ.
- For the simplest multi-threaded cache, when high availability is not needed, use Memcached.
- To store user sessions outside the instances, use ElastiCache or DynamoDB.
- For a cache with the least operational effort, use ElastiCache Serverless.
- To cache API responses without changing the application, use API Gateway caching.
- To require authentication to the cache, use ElastiCache with IAM or AUTH and encryption in transit.