What Is Amazon ElastiCache? Redis and Memcached on AWS Explained
A chai stall keeps a small kettle of ready tea for rush hour — not boiling every cup from cold water. ElastiCache is that kettle for your app: Redis or Memcached keep hot data in memory so DynamoDB/RDS is not hit for every page view.
In this chapter
- Why caching beats bigger databases alone
- Redis vs Memcached on ElastiCache
- Common patterns: cache-aside, session, leaderboard
- Security, failover, cluster mode basics
- Lab, errors, FAQ, interview
1. Everyday example first
A news site homepage hit RDS on every request. During elections CPU melted. Caching the homepage JSON in Redis for 30 seconds dropped DB load by ~90% with acceptable freshness.
Amazon ElastiCache is managed Redis (and Redis OSS / Valkey options as AWS evolves) and Memcached in-memory stores. You pick node type, clustering, Multi-AZ, and talk from your app over private network.
2. Redis vs Memcached
A cache holds a convenient copy so a read can be faster. Imagine a product page reads price and name from the database. The first request asks for key product:42, finds no entry and reads the database. The app stores the result with a time-to-live, or TTL, of 30 seconds. A second request before it expires can read that same value from the cache. This is a cache hit. The first was a miss. Pick the engine based on the kind of data and operations you need, such as simple values versus a sorted leaderboard.
| Need | Prefer | Why |
|---|---|---|
| Sessions, leaderboards, locks, pub/sub | Redis | Rich data structures + persistence options |
| Simple object cache, many nodes, multi-thread | Memcached | Simple and horizontally easy |
| Need recovery after a cache failure | Valkey or Redis OSS with supported snapshots and replication | Snapshots can restore a prior copy. Multi-AZ replicas can shorten recovery time. Keep durable business data in the source of truth. |
| Lowest ops for key-value only | Either — often Redis by default in 2026 shops |
3. Patterns
Now change the product price in the database. A user who reads the cached copy may still see the old price until the cache is updated, removed or expires. In your notes, draw the read sequence at 0 seconds, 15 seconds and after expiry, with the update happening at second 10. Compare the results for a short TTL and for an invalidation that succeeds immediately. That lets you choose a freshness target based on what the user sees, not only on how many reads spared the database.
- Cache-aside (lazy): app reads cache; on miss loads DB and fills cache.
- Write-through: update the database, then refresh the cache. If a product price changes from 500 to 600 and the cache write fails after the database commits, the old value can still be served. Plan how to invalidate the old key and set a TTL that fits your freshness goal.
- Session store: sticky user session in Redis.
- Rate limiting / counters: INCR with TTL.
- Leaderboard: Redis sorted sets.
Ravindra Bagale's Tip
Cache is not a database. If Redis evaporates, your app must still rebuild from the source of truth.
4. Security and networking
- Place nodes in private subnets; security group only from app SG.
- Use AUTH / ACL (Redis) and encryption in-transit when available.
- Do not expose Redis to 0.0.0.0/0 — ever.
- IAM auth options exist for some engines — prefer over long passwords in code; use Secrets Manager.
5. Industries
- Ecommerce: product page and cart fragment cache.
- Gaming: leaderboards and presence.
- Fintech: short-lived OTP / session tokens.
- Media: hot metadata for video catalogs.
- SaaS: multi-tenant rate limits per API key.
6. Mini lab: Redis cache-aside notes
Keep the same product key across the exercise. Record one miss and fetch from the source, then one hit before expiry. Change the source value, expire or remove the cache entry in the lab, and confirm the following fetch sees the new value. A missing cache should still let your small app read the source. In a real lab use a private cache and remove only the training key and resources.
Do this in ap-south-1 (Mumbai) unless your org forbids it. Set a budget alert first.
- Create a small ElastiCache Redis (cache.t3.micro or current burstable lab size) in private subnet — expect cost; use short TTL lab.
- From a bastion/EC2 in same VPC, redis-cli PING.
- SET lab:hello world EX 60 then GET.
- Sketch cache-aside in your app language on paper.
- CloudWatch: CurrConnections, Evictions, CPU.
Cleanup (stop billing)
- Delete the cluster — Redis bills while available.
- Remove bastion if only for lab.
7. Common errors and fixes
Each row is a real mistake students and juniors hit. Read the fix before you panic.
| Error / symptom | Fix |
|---|---|
| TIMEOUT from app | SG/NACL/subnet route; Redis not public. |
| OOM / evictions spike | Keys without TTL or tiny node — raise memory or TTL. |
| Stampede after expiry | Soft TTL / probabilistic early refresh / lock. |
| Cluster mode keyslot errors | Hash tags for multi-key ops; understand slots. |
| Failover surprise | Test replica promotion in staging. |
| Cached personal data too long | Short TTL + encryption; respect privacy. |
| Using cache as queue forever | Use SQS/Kafka for queues. |
| Wrong engine version client | Match redis-py / lettuce versions. |
| Multi-AZ off in prod | Enable for prod Redis. |
| Bill after "stopped" | ElastiCache is deleted not stopped like EC2 — delete cluster. |
8. Troubleshooting checklist
- Security group: app → Redis port (6379 default) only.
- Same VPC / peered path exists.
- AUTH token correct from Secrets Manager.
- TLS flag matches cluster setting.
- Monitor Evictions and CPU before scaling vertically.
9. FAQ
Q. ElastiCache vs DynamoDB DAX?
DAX is DynamoDB-specific acceleration; ElastiCache is general Redis/Memcached.
Q. Redis persistence on ElastiCache?
Replicas + optional persistence features — still design for cache loss.
Q. Memcached dead?
Still valid for simple caches; Redis dominates feature requests.
Q. Serverless ElastiCache?
AWS has been expanding serverless cache options — check current console for your region.
Q. How big should TTL be?
Business freshness: homepage 30s; profile 300s; config 60s — measure.
10. Interview Q&A
Q. What is ElastiCache?
Managed Redis/Memcached in-memory store on AWS.
Q. Cache-aside?
Read cache; on miss read DB and populate cache with TTL.
Q. Redis vs Memcached?
Redis: rich structures; Memcached: simple multi-node KV.
Q. How do you secure it?
Private subnets, tight SG, AUTH/ACL, encryption, no public access.
Q. Thundering herd?
Dogpile lock / staggered TTL / soft expire.
Q. When not to cache?
Strongly consistent writes every read must see; tiny rarely-read datasets.
11. Tips in English, Marathi and Hindi
Ravindra Bagale's Tip (EN)
Put TTL on every key in labs and in prod unless you have a written exception.
Ravindra Bagale's Tip (MR)
Lab आणि prod मध्ये प्रत्येक key ला TTL — लिहिलेली exception सोडून.
Tip (HI)
हर key पर TTL रखो — लिखित exception छोड़कर।
Try at home
- Draw cache-aside for a product API on paper.
- Compare Redis vs Memcached in 5 bullets for an interview.
- Estimate monthly cost of cache.t3.micro in ap-south-1 (pricing page).
In short
- ElastiCache = managed in-memory Redis/Memcached.
- Prefer Redis for most app patterns in 2026.
- Private + AUTH + TTL always.
- Delete lab clusters — they bill while available.
Revision, interview and comparison cards
Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.











More cards: Ravi Sir's Cards.
Practise this chapter
Interview questions and answers
A database price changed, but the browser still shows the old one. How do you investigate the cache?
Read the source value, the cached value and the cache key’s expiry. Check whether the app’s update or invalidation ran. Remove the test key or let it expire and verify the next read brings in the new value. Choose freshness based on what users need.
Check your understanding
Choose an answer, then compare your reasoning with the explanation.
Practice Tasks
Practice checks run in your browser. They check the answer for this exercise; they do not create resources or connect to your AWS account.
About this scenarioShivneri Schools is a education business in Junnar. Kavita Shinde looks after its IT and cloud work. They count money in INR and run their AWS resources in the ap-south-1 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.
0 / 16
Easy Describe cache clusters
See Redis/Memcached.
Describe cache clusters in ap-south-1.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Easy Delete cache cluster
Stop lab cost.
Delete cache cluster shivnerischool-redis.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Easy Describe cache subnet groups
Place cache in VPC.
Describe cache subnet groups.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Easy Describe parameter groups
Tune redis params.
Describe cache parameter groups.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Easy Default Redis port
Security groups need the port.
Default Redis port number?
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Easy Default Memcached port
Different from Redis.
Default Memcached port number?
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Medium Reboot cache cluster
Apply maintenance.
Reboot cache cluster shivnerischool-redis.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Medium Create cache subnet group
Multi-AZ placement.
Create cache subnet group shivnerischool-sub with subnet-ids subnet-aaa subnet-bbb description lab.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Medium Modify cluster node type
Scale vertically.
Modify cache cluster shivnerischool-redis to cache-node-type cache.t3.small apply-immediately.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Medium Describe replication groups
Redis HA.
Describe replication groups.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Medium Single-node Redis lab nodes
Lab uses one node.
How many cache nodes in a single-node Redis cluster?
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Medium Connection endpoint JSON
Apps need host and port.
JSON endpoint Address redis.example.cache.amazonaws.com Port 6379.
- Start from the top-level keys the task names.
- Indent child keys with 2 spaces (no tabs).
- Fill in each property with the value from the task.
- Click Check answer. Key order does not matter.
Hard Create Redis cluster
Session cache.
Create cache cluster shivnerischool-redis engine redis cache-node-type cache.t3.micro num-cache-nodes 1.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Hard Create Memcached cluster
Simple object cache.
Create cache cluster shivnerischool-mc engine memcached cache-node-type cache.t3.micro num-cache-nodes 2.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Hard Deny opening Redis to world
Never 0.0.0.0/0 on 6379 in prod stories.
Deny ec2:AuthorizeSecurityGroupIngress on *.
- Start with { "Version": "2012-10-17", "Statement": [ ... ] }.
- In each statement write Effect, Action and Resource.
- Give only what the task needs (least privilege).
- Use double quotes and commas correctly. Click Check answer.
Hard Auth token length rule quiz doc
Redis AUTH.
JSON auth with TokenLength 32 Min 16 Max 128.
- Start from the top-level keys the task names.
- Indent child keys with 2 spaces (no tabs).
- Fill in each property with the value from the task.
- Click Check answer. Key order does not matter.