← Back to Index
Chapter 13 of 20

ElastiCache & Caching Strategies

Domain 3 — High-Performing Architectures (24%)
💾
Question 1Scenario

A company needs a caching layer that supports complex data structures (sorted sets, lists, pub/sub messaging), automatic Multi-AZ failover, and data persistence to disk. Which ElastiCache engine should they choose?

Explanation

Redis vs Memcached: Redis supports data structures (strings, hashes, lists, sets, sorted sets), pub/sub, replication, Multi-AZ failover, persistence, backup/restore, and Lua scripting. Memcached is simpler: multi-threaded, horizontally scalable, but no replication, no persistence, no complex data types. Use Redis for most production caching needs.

Question 2Knowledge

Which caching strategy loads data into the cache only when a cache miss occurs — the application queries the cache first, and if not found, fetches from the database and populates the cache?

Explanation

Lazy Loading pros: only requested data is cached (efficient memory use). Cons: cache miss penalty (three trips: cache, DB, then cache write), possible stale data. Write-Through pros: data is always fresh. Cons: unused data occupies cache, write latency increases. Combining both strategies is common in production.

Question 3Scenario

A company uses ElastiCache Memcached with 5 cache nodes for session storage. One node fails. What happens to the user sessions stored on that node?

Explanation

Memcached is a simple, distributed cache with no replication or persistence. Data on a failed node is permanently lost. For session data requiring high availability, use ElastiCache Redis (which supports replication and Multi-AZ) or store sessions in DynamoDB. This is a key exam differentiator between Memcached and Redis.

Question 4Knowledge

Which caching strategy writes data to both the cache and the database on every write operation, ensuring the cache is always up to date?

Explanation

Write-Through: every write updates both cache and database. Pros: data in cache is always fresh, no stale reads. Cons: write operations have additional latency, and the cache fills with data that may never be read (wasted memory). Best combined with a TTL to expire unused cached items.

Question 5Scenario

An ElastiCache Redis cluster fails over from the primary to a replica. A small amount of data written to the primary just before the failure is not present on the new primary. Why does this happen?

Explanation

ElastiCache Redis replication is asynchronous, meaning the primary acknowledges writes before they are replicated to read replicas. During a failover, the newly promoted replica may be slightly behind the primary (replication lag), resulting in potential data loss of the most recent writes. This is a known trade-off in Redis Multi-AZ configurations.