ElastiCache and choosing a database

Intermediate · 20 min

Caching with ElastiCache and Valkey: cache-aside, write-through, expiry and failure, plus how to choose between AWS database services.

Before thisRDS engines and operationsAuroraDynamoDB tables, keys and queries

AWS Developers · 20 min

ElastiCache and choosing a database

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by AWS DevelopersReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • A cache keeps copies of expensive answers in memory. It must be safe to lose, and the application must cope when it is empty.
  • Cache-aside loads on a miss and invalidates on write. Write-through updates the cache with every write.
  • Give every entry a TTL. It bounds how long a stale value can survive the races that invalidation misses.
  • ElastiCache offers Valkey, Redis OSS and Memcached, either serverless or as node-based clusters.
  • Guard against stampedes and hot keys, and check that the database survives a cold cache.
  • Choose a database from access patterns, consistency and operating effort. Start with one general store and add others for a measured reason.

Asking the same question again

Your product page runs the same six queries for every visitor. The answers change a few times a day. Computing them ten thousand times a minute wastes the one component that’s hardest to scale. A cache keeps recent answers in memory, where reads take well under a millisecond. It’s the sticky note on your monitor: quicker than the filing cabinet, and wrong the moment someone updates the cabinet without telling you.

Distributed caching and caching strategies cover the general patterns. Here’s the AWS side.

ElastiCache

Amazon ElastiCache is managed in-memory storage running Valkey, Redis OSS or Memcached. Valkey is the open-source fork of Redis and the sensible default for new work. Memcached is a simple multithreaded key-value cache. Valkey and Redis add data structures, replication and failover.

Serverless caches scale for you behind one endpoint and bill for data stored and work done. Node-based clusters let you choose node types, shards and replicas, and can cost less for steady load. Either is normally reached from inside your VPC; serverless also offers a public endpoint option that requires IAM authentication and TLS. With Multi-AZ and replicas, a failed primary is replaced by promotion. Replication is asynchronous by default, so recent writes can be lost.

Patterns

Cache-aside (lazy loading): read the cache; on a miss read the database and fill it. After a write, delete the key. Only requested data gets cached, and a cache outage costs speed rather than correctness.

Write-through: update the cache whenever you write. Reads are warm, but you cache things nobody reads, and two writes to two systems can disagree.

Cache-aside has a race. I simulated it with two dictionaries, letting a write slip in between a reader’s database load and its cache fill:

after a normal write: 12
database: 15  cache: 12

The reader stored a value that was already old, after the writer’s invalidation had run. Nothing will fix it until the entry expires. So always set a TTL, chosen by how stale you can bear.

When caches hurt

  • Stampede: a hot key expires and every request rebuilds it. Use a lock or early refresh, and jitter TTLs.
  • Hot key: one key overloads one shard. Copy it, or cache it in the application too.
  • Cold start: after a flush or replacement, all load hits the database. Know whether it survives.
  • Memory pressure: entries are evicted by policy. Watch evictions and hit rate.

Code with short timeouts and treat a cache error as a miss. Measure first: an index is often a better fix than a cache.

Choosing a database

Need Look at
relations, joins, transactions RDS or Aurora
key access at any scale, little operation DynamoDB
speed in front of another store ElastiCache
durable in-memory primary store MemoryDB
MongoDB-compatible documents DocumentDB
Cassandra-compatible tables Keyspaces
graph traversal Neptune
full-text search and log search OpenSearch Service
analytics over large history Redshift, or Athena over S3

The list changes. Amazon QLDB, still shown in older material, reached end of support in July 2025, and Timestream for LiveAnalytics has been closed to new customers since June 2025. Check a service’s current status before designing around it.

Ask in order. What are the reads and writes? What must be consistent? How big will it get, and how spiky? What can your team operate? Leaving each store costs real migration work. Most applications start well with one relational database or DynamoDB. Each extra store adds a copy to synchronize, back up and secure, so add one when a measurement calls for it. Choosing a data model goes further.

About the video

The embed is AWS Developers’ 20-minute “The Caching Mistake Slowing Down Your AWS App” from March 2026. Its chapters cover cache-aside, write-through, the gotchas of caching and implementing Valkey on ElastiCache. It is about caching only; it doesn’t compare databases, which the link from Be A Better Dev does briefly and with an older service line-up. I judged it from chapters and description; its audio is flagged as original US English.

What was run: the race is a dictionary simulation in Python, not ElastiCache or Valkey. Service facts come from AWS documentation, checked in November 2026.

Check yourself

  1. 01After an update you delete the cache key, yet the old value sometimes reappears. How?

    A reader that missed before the update can fetch the old value and write it into the cache after your delete. A TTL limits the damage; versioned keys or conditional fills prevent it.

  2. 02A popular key expires and the database is hit by thousands of identical queries. What is this and what helps?

    A cache stampede. Let one request rebuild the value behind a lock, refresh early, and add random jitter to TTLs.

  3. 03Why is a plain ElastiCache cache a poor sole home for order records?

    It is designed as a cache. Entries can be evicted or lost on failover. Records belong in a durable database, or in a store designed for durability such as MemoryDB.

  4. 04Your workload is fetching sessions by ID at huge, spiky volume. Which fits better, RDS or DynamoDB?

    DynamoDB. Access is by key, volume is spiky, there are no joins, and it needs no connection management or instance sizing.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark