ElastiCache
✅ What is ElastiCache?¶
AWS ElastiCache is a fully managed, in-memory data store service for Redis and Memcached, used to speed up applications by caching frequent queries or data.
🚀 Benefits¶
-
⚡ Ultra-low latency (microseconds)
-
🔁 Redis clustering and failover
-
🛡️ Secure (IAM, VPC, encryption)
-
📈 Auto-backup and monitoring
🔄 Supported Engines¶
| Engine | Use Case |
|---|---|
| Redis | Caching, Pub/Sub, Sessions |
| Memcached | Lightweight, no persistence |
📊 Architecture (Redis Example)¶
+-------------------------+
| Application Tier |
| (EC2 / Lambda / ECS / EKS)
+-----------+-------------+
|
v
+----------------------+
| ElastiCache Proxy | (Optional)
+----------------------+
|
+----------------------+
| ElastiCache Redis |
|----------------------|
| Primary Node |
| + Replica Nodes |
+----------------------+
|
Auto failover & replication (if enabled)
🔁 Workflow¶
-
🏃 App sends read/write request to Redis endpoint
-
🔍 If data exists in Redis → return (cache hit)
-
❌ If not → fetch from DB, then store in Redis (cache miss)
-
🔁 Optional: Replicas handle read traffic
-
🔄 TTL expires or is invalidated when updated in DB
🔐 High Availability (Redis Only)¶
-
Multi-AZ replication
-
Automatic failover to replica node
-
Cluster mode (sharding) for scalability
🔧 Common Use Cases¶
-
✅ API/data caching (e.g., product details)
-
✅ Session storage (web apps)
-
✅ Leaderboards (gaming)
-
✅ Real-time metrics (IoT, dashboards)
-
✅ Pub/Sub systems
🛠️ Sample Terraform (Redis)¶
resource "aws_elasticache_subnet_group" "example" {
name = "example-subnet"
subnet_ids = ["subnet-123", "subnet-456"]
}
resource "aws_elasticache_replication_group" "redis" {
replication_group_id = "my-redis-group"
replication_group_description = "Redis HA"
node_type = "cache.t3.micro"
number_cache_clusters = 2
engine = "redis"
automatic_failover_enabled = true
subnet_group_name = aws_elasticache_subnet_group.example.name
}