Amazon ElastiCache
Amazon ElastiCache is a fully managed in-memory caching service that supports two open-source in-memory caching engines: Redis (and now Valkey) and Memcached. It improves application performance by retrieving data from fast, managed, in-memory caches instead of relying entirely on slower disk-based databases.
Engines
- Redis (and Valkey):
- Features: Supports complex data structures (sorted sets, hashes, lists), persistence (AOF/RDB), Pub/Sub, Multi-AZ (Automatic Failover), and Read Replicas (Cluster Mode).
- Use Case: Leaderboards, geospatial data, complex caching, session stores, chat apps.
- Valkey: A Linux Foundation open-source evolution of Redis OSS, priced lower than Redis.
- Memcached:
- Features: Simple key-value store, multi-threaded (scales up well on large multicore nodes). No persistence, no replication (in the traditional sense), no Multi-AZ failover (nodes are replaced if they fail).
- Use Case: Simple object caching, offloading DBs (HTML fragments, API calls).
Key Features
- Extreme Performance: Microsecond latency for read-heavy workloads.
- fully Managed: Automates patching, failure detection, and backups (Redis only).
- Serverless: New option that automatically scales capacity based on demand without managing nodes.
- Global Datastore (Redis): Replicate data across regions for low latency and DR.
- Data Tiering: Use local SSDs to store cooling data (Redis only) for cost savings.
Exam Tips
- "High performance / Microsecond latency": Think ElastiCache or DynamoDB Accelerator (DAX). If it's for a relational DB (RDS), it's ElastiCache. If it's for DynamoDB, it's DAX.
- Redis vs Memcached:
- Redis: Complex data types, persistence, high availability (Multi-AZ), backup/restore, sorted sets (leaderboards).
- Memcached: Simple Key-Value, Multi-threaded, pure caching (no persistence).
- Session State: Excellent use case for ElastiCache (share sessions across stateless web servers).
- Lazy Loading vs Write Through:
- Lazy Loading: Load data into cache only when necessary (can cause stale data).
- Write Through: specialized code adds data to cache whenever it writes to DB (data never stale, but write penalty).
Common Use Cases
- Database caching (RDS).
- User session storage (ShoppingCart).
- Real-time gaming leaderboards (Redis Sorted Sets).
- Geospatial queries.