AWS ElastiCache vs MemoryDB: Which One Do You Actually Need?

Published: (December 24, 2025 at 06:50 PM EST)
2 min read
Source: Dev.to

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 caseImpact if Redis dies
Rate‑limiting counters (user:123:requests:minute)Counters reset to 0 – users get a fresh minute; not a big deal
Session cachingSessions expire – users log in again; minor inconvenience
Temporary feature flagsFlags 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)

ServiceNode typeApprox. monthly cost
ElastiCachecache.t4g.micro~$12
ElastiCachecache.t4g.small~$24
MemoryDBdb.t4g.small~$25
MemoryDBdb.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

FeatureRedis CloudIn‑VPC ElastiCache
AuthenticationUsername/password, TLS, credential rotationNo password needed (security group controls access)
Network dependencyExternal serviceNo external dependency
LatencyHigher (internet)Lower (within VPC)

Migration tips (Redis Cloud → ElastiCache)

  1. Update connection settings: host, port, and remove auth.
  2. Accept that the cache starts empty – design your app to handle empty caches gracefully.
  3. For rate limiting and caching, the migration is trivial because the data is ephemeral.

Use‑case matrix

Use caseRecommended serviceReason
Rate limitingElastiCacheEphemeral, can regenerate
Session cacheElastiCacheCan re‑authenticate if lost
Page cacheElastiCacheCan re‑render if lost
Leaderboard (source of truth)MemoryDBRankings cannot be regenerated
Shopping cart (no DB backup)MemoryDBUser data must not be lost
Real‑time inventoryMemoryDBBusiness‑critical
Pub/Sub messagingDependsIf 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.

Back to Blog

Related posts

Read more »

Launch an AWS EC2 Instance

Introduction This guide walks you through launching an AWS EC2 instance, installing Docker, and running NGINX inside a Docker container. By the end you will ha...