AWS ElastiCache vs MemoryDB: Which One Do You Actually Need?
Source: Dev.to
Decision guide
Is your data ephemeral (can be regenerated or lost)?
- YES → Use ElastiCache (≈ $12 / month for
cache.t4g.micro) - NO → Use MemoryDB (≈ $25 +/ month, durable storage)
That’s the whole decision.
Why I chose ElastiCache for jo4.io
I need Redis for:
| Use case | Impact if Redis dies |
|---|---|
Rate‑limiting counters (user:123:requests:minute) | Counters reset to 0 – users get a fresh minute; not a big deal |
| Session caching | Sessions expire – users log in again; minor inconvenience |
| Temporary feature flags | Flags reload from the database; brief hiccup |
Since all of these are ephemeral, ElastiCache is the appropriate choice.
When to consider MemoryDB
MemoryDB is suited for scenarios where Redis holds the source of truth:
- Leaderboards / rankings that cannot be recalculated
- Real‑time inventory where Redis is the database
- Session data you can’t afford to lose (e.g., financial applications)
- Message queues where lost messages mean lost transactions
MemoryDB benefits
- Multi‑AZ durability (data survives node failures)
- Transaction log durability (writes are persisted)
- Point‑in‑time recovery
Cost comparison (small production workload)
| Service | Node type | Approx. monthly cost |
|---|---|---|
| ElastiCache | cache.t4g.micro | ~$12 |
| ElastiCache | cache.t4g.small | ~$24 |
| MemoryDB | db.t4g.small | ~$25 |
| MemoryDB | db.r6g.large | ~$200+ |
MemoryDB does not offer a micro tier, so its minimum cost is higher.
Example: Terraform for an ElastiCache cluster
resource "aws_elasticache_cluster" "redis" {
cluster_id = "jo4-prod-redis"
engine = "redis"
engine_version = "7.1"
node_type = "cache.t4g.micro"
num_cache_nodes = 1
port = 6379
parameter_group_name = "default.redis7"
subnet_group_name = aws_elasticache_subnet_group.redis.name
security_group_ids = [aws_security_group.redis.id]
# Daily snapshot, 7‑day retention (even for ephemeral data)
snapshot_retention_limit = 7
snapshot_window = "02:00-03:00"
maintenance_window = "sun:03:00-sun:04:00"
}
One advantage of ElastiCache: no authentication is required when accessed from within your VPC.
Example: Spring Boot Redis configuration (YAML)
spring:
data:
redis:
host: ${REDIS_HOST}
port: ${REDIS_PORT}
timeout: 5000
# No password needed – security group controls access
Comparison with Redis Cloud
| Feature | Redis Cloud | In‑VPC ElastiCache |
|---|---|---|
| Authentication | Username/password, TLS, credential rotation | No password needed (security group controls access) |
| Network dependency | External service | No external dependency |
| Latency | Higher (internet) | Lower (within VPC) |
Migration tips (Redis Cloud → ElastiCache)
- Update connection settings: host, port, and remove auth.
- Accept that the cache starts empty – design your app to handle empty caches gracefully.
- For rate limiting and caching, the migration is trivial because the data is ephemeral.
Use‑case matrix
| Use case | Recommended service | Reason |
|---|---|---|
| Rate limiting | ElastiCache | Ephemeral, can regenerate |
| Session cache | ElastiCache | Can re‑authenticate if lost |
| Page cache | ElastiCache | Can re‑render if lost |
| Leaderboard (source of truth) | MemoryDB | Rankings cannot be regenerated |
| Shopping cart (no DB backup) | MemoryDB | User data must not be lost |
| Real‑time inventory | MemoryDB | Business‑critical |
| Pub/Sub messaging | Depends | If message loss = money loss → MemoryDB |
Bottom line
- ElastiCache: Fast, cheap, ideal for caching and rate limiting where data loss is acceptable.
- MemoryDB: Durable, more expensive, for cases where Redis is the primary data store.
Don’t overthink it. If you can regenerate the data, go with ElastiCache.