By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
For AWS Solutions Architect – Associate (SAA-C03) and Real-World Production
You’re a cloud engineer at a fast-growing e-commerce startup. Your monolithic app is slowing to a crawl during Black Friday sales because every user request hits the database for session data (e.g., shopping carts, login status). Your CTO demands a fix today—without rewriting the app.
Enter ElastiCache: AWS’s managed in-memory caching service. It sits between your app and database, slashing latency from 100ms (DB query) to <1ms (cache hit). But here’s the catch: - Redis and Memcached are not interchangeable. Pick wrong, and you’ll either: - Lose data (Memcached’s lack of persistence). - Pay 2x more (Redis’s replication overhead). - Fail compliance (Redis’s encryption-at-rest vs Memcached’s none).
This guide gives you: ✅ Decision matrix (Redis vs Memcached) for session state.✅ Step-by-step deployment of a Redis cluster for session caching.✅ Production-ready configs (security, scaling, monitoring).✅ Exam traps (e.g., "Why can’t you use Memcached for multi-AZ failover?").
CacheHitRate
allkeys-lru
lru
volatile-lru
# Create a Redis cluster (Cluster Mode Disabled, 1 primary + 1 replica) aws elasticache create-cache-cluster \ --cache-cluster-id "session-cache" \ --cache-node-type "cache.t3.micro" \ --engine "redis" \ --engine-version "6.2" \ --num-cache-nodes 2 \ # 1 primary + 1 replica --az-mode "cross-az" \ # Multi-AZ failover --preferred-availability-zones "us-east-1a" "us-east-1b" \ --security-group-ids "sg-12345678" \ # Allow EC2/app access --snapshot-retention-limit 7 # Daily backups for 7 days
Verify:
aws elasticache describe-cache-clusters --cache-cluster-id "session-cache"
Look for CacheClusterStatus: available.
CacheClusterStatus: available
Python (Flask) Example:
import redis import os # Get Redis endpoint from AWS Console or CLI REDIS_ENDPOINT = os.getenv("REDIS_ENDPOINT", "session-cache.abc123.ng.0001.use1.cache.amazonaws.com") r = redis.Redis( host=REDIS_ENDPOINT, port=6379, password=None, # Enable Redis AUTH in production! decode_responses=True ) # Store session data r.set("user:123:cart", '{"items": ["book1", "book2"]}', ex=3600) # TTL: 1 hour # Retrieve session data cart = r.get("user:123:cart") print(cart) # Output: {"items": ["book1", "book2"]}
Node.js (Express) Example:
const redis = require("redis"); const client = redis.createClient({ url: "redis://session-cache.abc123.ng.0001.use1.cache.amazonaws.com:6379" }); client.connect().then(() => { client.set("user:123:cart", JSON.stringify({ items: ["book1"] }), { EX: 3600 }); client.get("user:123:cart").then(console.log); // Output: {"items": ["book1"]} });
# Set a password (replace "yourpassword" with a strong secret) aws elasticache modify-cache-cluster \ --cache-cluster-id "session-cache" \ --auth-token "yourpassword" \ --apply-immediately
Update your app code to include the password:
r = redis.Redis(..., password="yourpassword")
CPUUtilization
Evictions
bash aws elasticache modify-cache-cluster \ --cache-cluster-id "session-cache" \ --enable-cloudwatch-metrics
transit-encryption-enabled=true
cache.t3.micro
snapshot-retention-limit=7
Environment=prod
Purpose=session-cache
CacheHitRate < 80%
CPUUtilization > 70%
EX
expire
cross-az
❌ Memcached.
"You need to cache session data for a high-traffic app. Which engine is best?"
❌ Memcached (loses data on restart).
"How do you secure ElastiCache in a VPC?"
Redis vs Memcached: | Feature | Redis | Memcached | |------------------|---------------------|--------------------| | Persistence | ✅ Yes | ❌ No | | Multi-AZ | ✅ Yes | ❌ No | | Data Types | ✅ Strings, Lists, Sets | ❌ Strings only | | Cost | Higher (replication) | Lower |
Cluster Mode Disabled vs Enabled:
Scenario: Your Flask app stores user sessions in Redis. After a deployment, users report losing their shopping carts. Debug and fix the issue.
Solution: 1. Check Redis logs for evictions: bash aws elasticache describe-events --source-identifier "session-cache" 2. If Evictions > 0, increase node size: bash aws elasticache modify-cache-cluster \ --cache-cluster-id "session-cache" \ --cache-node-type "cache.t3.small" \ --apply-immediately 3. Why it works: Evictions happen when the cache is full. Scaling up gives more memory.
bash aws elasticache describe-events --source-identifier "session-cache"
Evictions > 0
bash aws elasticache modify-cache-cluster \ --cache-cluster-id "session-cache" \ --cache-node-type "cache.t3.small" \ --apply-immediately
6379
11211
AUTH yourpassword
SET key value EX 3600
set key value 0 3600
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.