Ravindra BagaleCourses & study guides मराठी Track your progress

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.

What you'll learn 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

Why do we need this?

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.

What is it?

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.

Cache-asideApp needs keyRedis hit? returnMiss → read DBWrite value to Redis + TTL
Always set TTL — eternal keys become stale lies.

2. Redis vs Memcached

NeedPreferWhy
Sessions, leaderboards, locks, pub/subRedisRich data structures + persistence options
Simple object cache, many nodes, multi-threadMemcachedSimple and horizontally easy
Must survive node restart with dataRedis with suitable persistence/replAOF/RDB + replicas
Lowest ops for key-value onlyEither — often Redis by default in 2026 shops

3. Patterns

  • Cache-aside (lazy): app reads cache; on miss loads DB and fills cache.
  • Write-through: write DB and cache together (more consistent, more writes).
  • 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

Do this in ap-south-1 (Mumbai) unless your org forbids it. Set a budget alert first.

How to do it (step by step)

  1. Create a small ElastiCache Redis (cache.t3.micro or current burstable lab size) in private subnet — expect cost; use short TTL lab.
  2. From a bastion/EC2 in same VPC, redis-cli PING.
  3. SET lab:hello world EX 60 then GET.
  4. Sketch cache-aside in your app language on paper.
  5. CloudWatch: CurrConnections, Evictions, CPU.

Cleanup (stop billing)

  1. Delete the cluster — Redis bills while available.
  2. 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 / symptomFix
TIMEOUT from appSG/NACL/subnet route; Redis not public.
OOM / evictions spikeKeys without TTL or tiny node — raise memory or TTL.
Stampede after expirySoft TTL / probabilistic early refresh / lock.
Cluster mode keyslot errorsHash tags for multi-key ops; understand slots.
Failover surpriseTest replica promotion in staging.
Cached personal data too longShort TTL + encryption; respect privacy.
Using cache as queue foreverUse SQS/Kafka for queues.
Wrong engine version clientMatch redis-py / lettuce versions.
Multi-AZ off in prodEnable for prod Redis.
Bill after "stopped"ElastiCache is deleted not stopped like EC2 — delete cluster.

8. Troubleshooting checklist

  1. Security group: app → Redis port (6379 default) only.
  2. Same VPC / peered path exists.
  3. AUTH token correct from Secrets Manager.
  4. TLS flag matches cluster setting.
  5. 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

  1. Draw cache-aside for a product API on paper.
  2. Compare Redis vs Memcached in 5 bullets for an interview.
  3. Estimate monthly cost of cache.t3.micro in ap-south-1 (pricing page).

In short

  1. ElastiCache = managed in-memory Redis/Memcached.
  2. Prefer Redis for most app patterns in 2026.
  3. Private + AUTH + TTL always.
  4. 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.

Revision card: What is Amazon ElastiCache?. Every product-page hit querying RDS for the same row wastes time and money. ElastiCache is managed Redis or Memcached in your VPC for low-latency caching and some Redis data structures. Create a cache subnet group → security group → Redis cluster/replication group → connect from app in VPC. GET product:42 hits Redis in sub-ms after the first DB fill.
Revision card: What is Amazon ElastiCache? · Download PNG · Open card page
Revision card: Redis vs Memcached. Picking Memcached when you need locks or streams forces a painful migrate later. Redis: rich types, replication, persistence options, common default. Memcached: simple multi-node object cache. Choose Redis unless you have a clear Memcached-only pattern and tooling. Session store + rate limit counters fit Redis; a pure blob cache can use either.
Revision card: Redis vs Memcached · Download PNG · Open card page
Revision card: Cache-aside pattern. Writing only to cache and never to DB loses data on flush. Cache-aside: app reads cache; on miss read DB and fill cache; writes go to DB then invalidate or update cache. Implement getOrLoad(key) with short TTL; delete key on product update. After price update, next read refreshes from DB instead of serving stale price forever.
Revision card: Cache-aside pattern · Download PNG · Open card page
Revision card: Security group for cache. Opening Redis 6379 to the world is a common breach pattern. Place cache in private subnets; allow 6379/11211 only from app security groups. App SG egress OK; cache SG inbound from app SG id, never 0.0.0.0/0. App connects; a laptop on the internet cannot reach the cache endpoint.
Revision card: Security group for cache · Download PNG · Open card page
Revision card: Failover and evictions. A full cache that evicts hot keys can look like a DB outage. Use Multi-AZ / replicas for Redis HA. Watch Evictions and CPU; raise memory or TTL strategy when evictions spike. Enable Multi-AZ with auto-failover for prod Redis; alarm on Evictions > threshold. Primary failure promotes replica; app using the primary endpoint configuration reconnects.
Revision card: Failover and evictions · Download PNG · Open card page
Comparison: Redis (ElastiCache) vs Memcached (ElastiCache). Redis (ElastiCache): Structures, replication, snapshots, rich commands. Memcached (ElastiCache): Simple distributed object cache.
Comparison: Redis (ElastiCache) vs Memcached (ElastiCache) · Download PNG · Open card page
Comparison: Cache-aside vs Write-through. Cache-aside: App reads DB on miss, then fills cache. Write-through: App writes DB and cache together on update.
Comparison: Cache-aside vs Write-through · Download PNG · Open card page
Interview card: When do you add ElastiCache?. When the same reads hammer the DB and latency or cost suffers — after measuring. Not a replacement for a database of record. Product detail pages with hot keys are a classic cache-aside case.
Interview card: When do you add ElastiCache? · Download PNG · Open card page
Interview card: Redis or Memcached?. Default Redis for structures, replication, and wider ecosystem. Memcached for simple distributed object cache. Need counters, TTL keys, pub/sub-ish patterns → Redis. Session store almost always Redis on AWS today.
Interview card: Redis or Memcached? · Download PNG · Open card page
Interview card: How do you avoid cache stampede?. Stampede: many clients miss at once and crush the DB. Use TTL jitter, singleflight/lock on fill, or warm hot keys after deploy. Expire product keys with random skew so they do not align on the minute.
Interview card: How do you avoid cache stampede? · Download PNG · Open card page
Interview card: How do you pick cache TTL?. Balance freshness vs DB load; use shorter TTL for prices, longer for rare-changing catalogs; add jitter. Measure hit ratio and stale-read complaints after changes. Product title TTL 10 minutes ± jitter; cart contents often not cached or very short.
Interview card: How do you pick cache TTL? · Download PNG · Open card page

More cards: Ravi Sir's Cards.

Practice Tasks

About this scenario

Shivneri 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

Why: See Redis/Memcached.

What to do: Describe cache clusters in ap-south-1.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Delete cache cluster

Why: Stop lab cost.

What to do: Delete cache cluster shivnerischool-redis.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Describe cache subnet groups

Why: Place cache in VPC.

What to do: Describe cache subnet groups.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Describe parameter groups

Why: Tune redis params.

What to do: Describe cache parameter groups.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Default Redis port

Why: Security groups need the port.

What to do: Default Redis port number?

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy Default Memcached port

Why: Different from Redis.

What to do: Default Memcached port number?

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Reboot cache cluster

Why: Apply maintenance.

What to do: Reboot cache cluster shivnerischool-redis.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Create cache subnet group

Why: Multi-AZ placement.

What to do: Create cache subnet group shivnerischool-sub with subnet-ids subnet-aaa subnet-bbb description lab.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Modify cluster node type

Why: Scale vertically.

What to do: Modify cache cluster shivnerischool-redis to cache-node-type cache.t3.small apply-immediately.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Describe replication groups

Why: Redis HA.

What to do: Describe replication groups.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Single-node Redis lab nodes

Why: Lab uses one node.

What to do: How many cache nodes in a single-node Redis cluster?

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Connection endpoint JSON

Why: Apps need host and port.

What to do: JSON endpoint Address redis.example.cache.amazonaws.com Port 6379.

How:
  1. Start from the top-level keys the task names.
  2. Indent child keys with 2 spaces (no tabs).
  3. Fill in each property with the value from the task.
  4. Click Check answer. Key order does not matter.

Hard Create Redis cluster

Why: Session cache.

What to do: Create cache cluster shivnerischool-redis engine redis cache-node-type cache.t3.micro num-cache-nodes 1.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Hard Create Memcached cluster

Why: Simple object cache.

What to do: Create cache cluster shivnerischool-mc engine memcached cache-node-type cache.t3.micro num-cache-nodes 2.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Hard Deny opening Redis to world

Why: Never 0.0.0.0/0 on 6379 in prod stories.

What to do: Deny ec2:AuthorizeSecurityGroupIngress on *.

How:
  1. Start with { "Version": "2012-10-17", "Statement": [ ... ] }.
  2. In each statement write Effect, Action and Resource.
  3. Give only what the task needs (least privilege).
  4. Use double quotes and commas correctly. Click Check answer.

Hard Auth token length rule quiz doc

Why: Redis AUTH.

What to do: JSON auth with TokenLength 32 Min 16 Max 128.

How:
  1. Start from the top-level keys the task names.
  2. Indent child keys with 2 spaces (no tabs).
  3. Fill in each property with the value from the task.
  4. Click Check answer. Key order does not matter.