SAABlog
DatabaseIntermediate

ElastiCache Complete Guide: Redis vs Memcached - When to Use What?

Compare AWS ElastiCache Redis and Memcached. Learn selection criteria including data persistence, high availability, and data structures for SAA-C03 exam.

PHILOLAMB-Updated: January 31, 2026
ElastiCacheRedisMemcachedCachingIn-Memory

Related Exam Domains

  • Design High-Performing Architectures

Key Takeaway

Redis is the choice when you need complex data structures, data persistence, and high availability. Memcached is the choice when you need simple key-value caching with multi-threaded performance and data loss is acceptable.

Exam Tip

Exam Essential: "Cache with data persistence?" → Redis. "Simple caching + multi-thread?" → Memcached. "Pub/Sub messaging?" → Redis. "High availability + auto failover?" → Redis.


What is Amazon ElastiCache?

Concept

Amazon ElastiCache is a fully managed in-memory caching service providing microsecond latency. It supports Redis, Memcached, and the recently added Valkey engines.

┌─────────────────────────────────────────────────────────┐
│               ElastiCache Architecture                   │
├─────────────────────────────────────────────────────────┤
│                                                         │
│   Application                                           │
│       │                                                 │
│       ▼                                                 │
│   ┌───────────────────┐                                │
│   │    ElastiCache    │  ◀── Cache HIT: microseconds   │
│   │  (Redis/Memcached) │                                │
│   └─────────┬─────────┘                                │
│             │ Cache MISS                               │
│             ▼                                           │
│   ┌───────────────────┐                                │
│   │    RDS/Aurora     │  ◀── milliseconds to seconds   │
│   │    (Database)     │                                │
│   └───────────────────┘                                │
│                                                         │
│   Effect: Reduced DB load, improved response speed      │
└─────────────────────────────────────────────────────────┘

Supported Engines

EngineDescription
RedisAdvanced data structures, persistence, HA support
MemcachedSimple key-value, multi-threaded, lightweight
ValkeyRedis OSS fork, open-source compatible (new)

Redis Features

Core Capabilities

┌─────────────────────────────────────────────────────────┐
│                  Redis Key Features                      │
├─────────────────────────────────────────────────────────┤
│                                                         │
│  📊 Data Structures                                     │
│  ├── String: Simple key-value                          │
│  ├── List: Ordered collection (queue, stack)           │
│  ├── Set: Unique value collection                      │
│  ├── Sorted Set: Score-based sorting (leaderboards)    │
│  ├── Hash: Field-value pairs (object storage)          │
│  └── Bitmap, HyperLogLog, Stream, etc.                 │
│                                                         │
│  💾 Data Persistence                                    │
│  ├── Snapshot (RDB): Point-in-time backup              │
│  └── AOF: All write operation logging                  │
│                                                         │
│  🔄 High Availability                                   │
│  ├── Multi-AZ replication                              │
│  ├── Automatic failover                                │
│  └── Read Replicas                                     │
│                                                         │
│  📨 Pub/Sub Messaging                                   │
│  └── Real-time message publish/subscribe               │
└─────────────────────────────────────────────────────────┘

High Availability Configuration

┌─────────────────────────────────────────────────────────┐
│              Redis Multi-AZ Configuration                │
├─────────────────────────────────────────────────────────┤
│                                                         │
│   AZ-a                        AZ-b                      │
│   ┌──────────┐                ┌──────────┐             │
│   │ Primary  │ ─── Repl. ───▶ │ Replica  │             │
│   │ (Read/   │                │ (Read    │             │
│   │  Write)  │                │  Only)   │             │
│   └──────────┘                └──────────┘             │
│        │                           │                    │
│        └───────────────────────────┘                    │
│                    │                                    │
│                    ▼                                    │
│   Primary failure → Replica auto-promoted to Primary    │
│   (Automatic Failover)                                  │
└─────────────────────────────────────────────────────────┘

Cluster Mode

ModeDescription
Cluster Mode DisabledSingle shard, max 1 Primary + 5 Replicas
Cluster Mode EnabledMultiple shards, data partitioning, larger datasets

Memcached Features

Core Capabilities

┌─────────────────────────────────────────────────────────┐
│                 Memcached Key Features                   │
├─────────────────────────────────────────────────────────┤
│                                                         │
│  📊 Data Structures                                     │
│  └── String only (simple key-value)                    │
│                                                         │
│  🔧 Multi-threading                                     │
│  └── Can utilize multi-core CPUs                       │
│                                                         │
│  🔍 Auto Discovery                                      │
│  └── Automatic cluster node discovery                  │
│                                                         │
│  ❌ Unsupported Features                                │
│  ├── Data persistence (snapshot, backup)               │
│  ├── Replication                                       │
│  ├── Automatic failover                                │
│  └── Pub/Sub messaging                                 │
└─────────────────────────────────────────────────────────┘

Memcached Architecture

┌─────────────────────────────────────────────────────────┐
│              Memcached Cluster                           │
├─────────────────────────────────────────────────────────┤
│                                                         │
│   Node 1          Node 2          Node 3                │
│   ┌──────┐       ┌──────┐       ┌──────┐               │
│   │Key A │       │Key B │       │Key C │               │
│   │Key D │       │Key E │       │Key F │               │
│   └──────┘       └──────┘       └──────┘               │
│       │              │              │                   │
│       └──────────────┼──────────────┘                   │
│                      │                                  │
│                      ▼                                  │
│              Distributed data storage                   │
│              (No replication, node failure = data loss) │
└─────────────────────────────────────────────────────────┘

Exam Tip

Exam Point: Memcached does not support replication. When a node fails, that node's data is lost. If data loss is unacceptable, choose Redis.


Redis vs Memcached Comparison

Core Comparison Table

FeatureRedisMemcached
Data StructuresRich (String, List, Set, Hash, etc.)String only
Data Persistence✅ Snapshot, backup supported
Replication✅ Read Replicas
High Availability✅ Multi-AZ, auto failover
Pub/Sub
Transactions
Lua Scripting
Multi-threading❌ (single-threaded)
Management ComplexityHigherLower

Selection Flowchart

Start
  │
  ├── Need data persistence?
  │     ├── Yes → Redis
  │     └── No → Next question
  │
  ├── Need high availability (HA)?
  │     ├── Yes → Redis
  │     └── No → Next question
  │
  ├── Need complex data structures? (List, Set, Hash)
  │     ├── Yes → Redis
  │     └── No → Next question
  │
  ├── Need Pub/Sub messaging?
  │     ├── Yes → Redis
  │     └── No → Next question
  │
  └── Simple caching + multi-thread performance important?
        ├── Yes → Memcached
        └── No → Redis (default choice)

Recommendations by Use Case

Use CaseRecommended EngineReason
Session storeRedisPersistence, HA needed
Database query cachingEither worksSimple caching
Real-time leaderboardsRedisSorted Set usage
Real-time notificationsRedisPub/Sub usage
Shopping cartRedisHash, persistence
Page cachingMemcachedSimple, fast
Message queueRedisList usage

Cost Comparison

Node Costs

Hourly rates are the same for identical instance types.

Example: cache.r6g.large (Seoul Region)
├── Redis: $X.XXX/hour
└── Memcached: $X.XXX/hour (same)

Total Operating Cost Differences

FactorRedisMemcached
Node costSameSame
HA configurationReplica addition → cost increaseNo replication
Backup storageSnapshot storage costNone
Data transferMulti-AZ transfer costNone

Exam Tip

Cost Point: Redis Multi-AZ configuration requires minimum 2 nodes (Primary + Replica), potentially making total cost higher than Memcached.


ElastiCache Configuration

Redis Cluster Creation (Console)

1. ElastiCache Console → Create Redis cluster
2. Settings:
   ├── Cluster mode: Enable/Disable
   ├── Node type: cache.r6g.large
   ├── Replica count: 1-5
   ├── Multi-AZ: Enable
   └── Encryption: In-transit/At-rest
3. Select subnet group (within VPC)
4. Configure security group
5. Backup settings (retention period, backup window)

CLI Creation

# Redis Replication Group Creation
aws elasticache create-replication-group \
  --replication-group-id my-redis-cluster \
  --replication-group-description "My Redis cluster" \
  --engine redis \
  --cache-node-type cache.r6g.large \
  --num-cache-clusters 2 \
  --automatic-failover-enabled \
  --multi-az-enabled

Caching Strategies

Cache-Aside (Lazy Loading)

┌─────────────────────────────────────────────────────────┐
│                Cache-Aside Pattern                       │
├─────────────────────────────────────────────────────────┤
│                                                         │
│  1. Check cache                                         │
│     App ──▶ ElastiCache                                │
│              │                                          │
│              ├── Cache HIT → Return data               │
│              │                                          │
│              └── Cache MISS ─┐                         │
│                              │                          │
│  2. Query DB                 ▼                          │
│     App ──▶ Database ──▶ Return data                   │
│              │                                          │
│  3. Store in cache           │                          │
│     App ──▶ ElastiCache ◀────┘                         │
│                                                         │
│  Pros: Only caches needed data, resilient to cache fail │
│  Cons: First request slow, potential data inconsistency │
└─────────────────────────────────────────────────────────┘

Write-Through

┌─────────────────────────────────────────────────────────┐
│               Write-Through Pattern                      │
├─────────────────────────────────────────────────────────┤
│                                                         │
│  On Write:                                              │
│  App ──▶ ElastiCache ──▶ Database                      │
│          (cache store)   (DB store)                     │
│                                                         │
│  On Read:                                               │
│  App ──▶ ElastiCache ──▶ Return data                   │
│          (always HIT)                                   │
│                                                         │
│  Pros: Reads always fast, data consistency             │
│  Cons: Write latency, caches unnecessary data          │
└─────────────────────────────────────────────────────────┘

TTL (Time To Live)

# TTL Example (Python)
import redis

r = redis.Redis(host='my-cluster.cache.amazonaws.com')

# Store data with 1-hour TTL
r.setex('session:123', 3600, 'user_data')

# Retrieve
data = r.get('session:123')

Security Configuration

Encryption

OptionDescription
In-transit encryptionClient-server communication encryption using TLS
At-rest encryptionData encryption on disk (Redis only)

Authentication

Redis AUTH:
├── Basic AUTH: Single password
└── IAM Authentication: IAM role-based (Redis 6.0+)

Memcached:
└── SASL authentication supported

Network Security

┌─────────────────────────────────────────────────────────┐
│              ElastiCache Network Security                │
├─────────────────────────────────────────────────────────┤
│                                                         │
│  VPC Deployment:                                        │
│  ├── Private subnet recommended                        │
│  ├── Access control via security groups               │
│  └── VPC endpoints for AWS service connections        │
│                                                         │
│  Internet Access:                                       │
│  └── ElastiCache does not support public IPs          │
│      (Cannot access directly from internet)           │
└─────────────────────────────────────────────────────────┘

SAA-C03 Exam Focus Points

Common Question Types

  1. Feature Comparison

    • "Cache with data persistence support?" → Redis
    • "Pub/Sub messaging support?" → Redis
    • "Multi-thread support?" → Memcached
  2. High Availability

    • "Cache with automatic failover?" → Redis Multi-AZ
    • "Cache without replication support?" → Memcached
  3. Use Cases

    • "Suitable cache for session store?" → Redis (persistence, HA)
    • "Real-time leaderboards?" → Redis (Sorted Set)
    • "Simple page caching?" → Either works, Memcached recommended

Exam Tip

Key Memorization:

  • Redis = Persistence + Replication + HA + Rich data structures
  • Memcached = Simple + Multi-threaded + No persistence
  • In most cases, Redis is the answer (more features)

Frequently Asked Questions

Q: Which should I choose for session storage?

Redis is recommended. Sessions are critical to user experience, requiring data persistence and high availability. Sessions should persist even during node failures.

Q: What happens to data when a Memcached node fails?

That node's data is lost. Memcached doesn't support replication, so there's no recovery method when a node fails. The application must be able to handle cache misses.

Q: Is Redis more expensive?

Per-node cost is identical. However, Redis Multi-AZ configuration (adding replicas) can increase total cost. Memcached operating with single nodes may be cheaper in simple comparison.

Q: When should I choose Memcached?

When all of the following conditions apply:

  • Only simple key-value caching needed
  • Data loss acceptable (cache regeneratable)
  • High availability not required
  • Multi-thread performance is important

Q: When should I use Valkey?

Valkey is a fork of Redis OSS, chosen when you want to use open source without licensing concerns. Features are mostly compatible with Redis.


Summary

ElastiCache engine selection essentials:

RequirementChoice
Persistence neededRedis
High availability neededRedis
Complex data structuresRedis
Pub/Sub messagingRedis
Simple caching + data loss OKMemcached

Exam Tip: In most SAA exam scenarios, Redis is often the correct answer. Only choose Memcached when "simple caching", "multi-thread", or "data loss acceptable" is explicitly stated.



References