AWS Certified Solutions Architect – Associate
ElastiCache Redis vs Memcached, lazy loading vs write-through
Choose Memcached for the simplest cache of objects on large multi-threaded nodes that you scale out and in. Choose Valkey or Redis OSS when you need replication, automatic failover, backups, pub/sub, sorted sets or other complex data types. Then pick a strategy: lazy loading caches only what is read but can go stale, write-through keeps the cache current but leaves new nodes empty, and a TTL on each write limits staleness.
Choosing the engine
ElastiCache supports Valkey, Memcached and Redis OSS. All three are in-memory key-value stores. AWS says to choose Memcached when you need the simplest model, large nodes with multiple cores or threads, the ability to add and remove nodes as demand changes, and object caching. Memcached is multi-threaded; Valkey and Redis OSS are not.
Valkey and Redis OSS support complex data types such as sets, sorted sets, lists, hashes and geospatial indexes. They support replication for high availability, backup and restore, and pub/sub. Memcached on node-based clusters has none of these. Automatic failover is optional with cluster mode disabled and required with cluster mode enabled. Cluster mode enabled also partitions data across shards and allows online resharding.
Recent Valkey versions add features such as vector search (8.2) and full-text search and durability through a Multi-AZ transactional log (9.0). Data tiering between memory and SSD uses the r6gd node type.
Lazy loading
With lazy loading, the application reads from the cache first. On a miss it reads the database and writes the result to the cache. Only data that is requested gets cached, and a failed node is not fatal: a new, empty node fills up as misses come in.
The costs are a miss penalty of three trips (cache, database, cache write) and stale data, because nothing updates the cache when the database changes.
Write-through and TTL
With write-through, every database write also writes the cache, so cached data is never stale. Each write takes two trips. The costs are missing data on a new node until each item is written again, and cache churn, because most written data is never read. AWS says to reduce the missing-data problem by adding lazy loading alongside write-through.
A time to live (TTL) sets how many seconds a key lasts. An expired key is treated as a miss, so the application refetches it from the database. Adding a TTL to each write keeps data from getting too stale and clears out unread data, though it does not guarantee data is never stale.
Where the exam catches people
- Believing Memcached can fail over to a replica: Memcached node-based clusters have no replication or automatic failover; use Valkey or Redis OSS.
- Believing Valkey or Redis OSS is always the better pick: for simple, rebuildable objects on multi-core nodes that scale out and in, AWS points to Memcached.
- Believing write-through means a new node is warm: it holds nothing until each item is written again, so pair it with lazy loading.
- Believing lazy loading keeps data fresh: the cache is not updated when the database changes; add a TTL to bound staleness.
- Believing automatic failover is optional with cluster mode enabled: it is required there and optional only with cluster mode disabled.