SAA-C03Chapter 24 of 189Objective 3.1

Amazon ElastiCache: Redis vs Memcached

This chapter covers Amazon ElastiCache, focusing on the two caching engines: Redis and Memcached. For the SAA-C03 exam, understanding when to choose Redis vs. Memcached is critical, as questions often test your ability to select the appropriate caching solution based on application requirements. Approximately 5-10% of exam questions touch on ElastiCache, typically in the context of improving application performance, offloading database reads, or managing session state. By the end of this chapter, you will know the exact features, limitations, and use cases for each engine, including key trade-offs like persistence, replication, data structures, and multi-threading.

25 min read
Intermediate
Updated May 31, 2026

Warehouse vs. Tool Shed: Caching Engines

Imagine you run a busy restaurant kitchen. You have two ways to store frequently used ingredients: a large, climate-controlled warehouse (Redis) and a small, open-air tool shed (Memcached). The warehouse can store not just ingredients but also complex recipes, prep lists, and even temperature logs for each station. It has a manager (single-threaded event loop) who organizes everything carefully, ensuring no two cooks write conflicting instructions. The warehouse also automatically copies its contents to a backup warehouse across town (replication) and can even restore from a snapshot if the main one burns down (persistence). The tool shed, on the other hand, is just a simple shelf. It can only hold basic ingredients (key-value pairs with simple strings). Multiple cooks can access it simultaneously (multi-threaded), but if two cooks try to update the same ingredient list, the last one wins — no conflict resolution. The tool shed has no backup; if it collapses, everything is lost. For the exam, know that Redis is the full-featured warehouse for complex, durable caching, while Memcached is the lightweight, multi-threaded shed for simple, ephemeral data.

How It Actually Works

What is Amazon ElastiCache?

Amazon ElastiCache is a fully managed, in-memory caching service that provides a high-performance, low-latency data store for applications. It supports two open-source caching engines: Redis and Memcached. ElastiCache abstracts away the operational overhead of deploying, patching, and monitoring cache clusters, allowing you to focus on application logic.

Why Use ElastiCache?

The primary purpose of ElastiCache is to reduce latency and improve throughput by storing frequently accessed data in memory, thereby offloading the backend database (e.g., Amazon RDS, DynamoDB). Common use cases include: - Database query result caching: Store the results of expensive SQL queries to avoid repeated database hits. - Session management: Store user session data (e.g., shopping cart contents) in a centralized cache across multiple application instances. - Real-time analytics: Use Redis’s sorted sets for leaderboards or stream processing. - API rate limiting: Use Redis’s atomic increment operations to track request counts.

Redis vs. Memcached: Core Differences

#### Data Structures - Redis: Supports a wide variety of data structures: strings, hashes, lists, sets, sorted sets, bitmaps, hyperloglogs, geospatial indexes, and streams. This allows complex operations like intersection, union, and range queries directly on the server. - Memcached: Only supports simple key-value pairs where values are limited to strings up to 1 MB in size. No support for collections or complex data types.

#### Persistence - Redis: Offers optional persistence via snapshotting (RDB) or append-only file (AOF). RDB creates point-in-time snapshots at configurable intervals (e.g., every 5 minutes if at least 100 keys changed). AOF logs every write operation and can be configured for fsync every second or every write. This makes Redis suitable for use as a primary database (though ElastiCache for Redis is not recommended as a primary database for production; use RDS or DynamoDB instead). - Memcached: No persistence. Data is purely in-memory and lost on node failure or restart.

#### Replication and High Availability - Redis: Supports replication with a primary (master) node and up to 5 read replicas. ElastiCache for Redis also supports Multi-AZ with automatic failover, which promotes a read replica to primary if the primary fails. Redis Cluster mode enables automatic sharding across up to 500 shards (with 1 primary and up to 5 replicas per shard) for horizontal scaling. - Memcached: No replication. Data is sharded across nodes using consistent hashing (client-side or via auto-discovery). If a node fails, the data on that node is lost and must be reloaded from the source.

#### Multi-Threading - Redis: Single-threaded for command execution. This means Redis can handle a high volume of simple operations but may become CPU-bound for complex operations or large payloads. However, I/O threads and background tasks (like persistence) are handled by separate threads. - Memcached: Multi-threaded. It can utilize multiple CPU cores, making it better suited for workloads with large numbers of small objects and high throughput requirements.

#### Memory Management - Redis: Allows fine-grained memory management with configurable eviction policies: noeviction, allkeys-lru, allkeys-lfu, volatile-lru, volatile-lfu, allkeys-random, volatile-random, volatile-ttl. Redis also supports memory overcommitment and can use virtual memory (though not recommended). - Memcached: Uses a slab allocator to manage memory. Memory is divided into slabs of varying sizes (e.g., 64 bytes, 128 bytes, etc.). Items are stored in the smallest slab that fits their size. Memcached has a simpler eviction policy: LRU (least recently used) per slab class.

#### Scalability - Redis: Can scale vertically (larger node sizes) and horizontally using Redis Cluster (sharding). ElastiCache for Redis supports partitioning data across up to 500 shards, each with its own primary and replicas. - Memcached: Scales horizontally by adding nodes to a cluster. Data is distributed using consistent hashing. ElastiCache for Memcached supports up to 20 nodes per cluster (soft limit, can be increased).

#### Security - Both engines support encryption at rest (using KMS) and in transit (TLS). Redis also supports Redis AUTH (password) and Role-Based Access Control (RBAC) with multiple users and permissions. Memcached supports SASL-based authentication (though not enabled by default).

Key Configuration Parameters and Defaults

#### Redis Defaults (ElastiCache for Redis) - Default eviction policy: volatile-lru (evict least recently used keys among those with an expiration set). - Default port: 6379. - Maxmemory-policy: Configurable; can be changed to allkeys-lru for general LRU. - Snapshotting (RDB): Disabled by default in ElastiCache; you can enable it via parameter group. - AOF: Disabled by default. If enabled, you can set appendfsync to always, everysec, or no. - Replication: Up to 5 read replicas per primary. - Cluster mode: Disabled by default; can be enabled for sharding.

#### Memcached Defaults (ElastiCache for Memcached) - Port: 11211. - Max item size: 1 MB. - Memory: Allocates all available memory (minus overhead) to the cache. - Eviction policy: LRU per slab class. - Number of nodes: Up to 20 in a cluster. - Auto-discovery: Enabled by default; clients automatically discover all nodes.

How to Choose Between Redis and Memcached

The SAA-C03 exam will test your ability to select the appropriate engine based on requirements. Use the following decision criteria: - Need for complex data structures? Choose Redis (hashes, lists, sets, sorted sets, etc.). - Need persistence? Choose Redis. - Need high availability with automatic failover? Choose Redis with Multi-AZ. - Need to scale reads? Choose Redis with read replicas. - Need to cache simple key-value pairs with minimal overhead? Choose Memcached. - Need multi-threaded performance for many small objects? Choose Memcached. - Cost-sensitive and can tolerate data loss? Memcached is generally cheaper per GB of memory.

Interacting with Related AWS Services

ElastiCache often works alongside: - Amazon RDS: Cache database query results to reduce load. - Amazon DynamoDB: Use DynamoDB Accelerator (DAX) for microsecond latency, but ElastiCache can also cache DynamoDB responses. - AWS Lambda: Store session state or temporary data between invocations (though DynamoDB is more common for Lambda). - Amazon CloudFront: For caching static content at the edge, not a direct alternative.

Monitoring and Metrics

Both engines provide CloudWatch metrics: - CacheHits / CacheMisses: Ratio indicates effectiveness. - CurrConnections: Number of client connections. - Evictions: Number of keys evicted due to memory pressure. - CPUUtilization: For Redis, high CPU may indicate need for larger instance or sharding. - SwapUsage: High swap indicates memory pressure.

Common Commands and Operations

#### Redis CLI examples:

# Connect to ElastiCache Redis endpoint
redis-cli -h mycache.xxxxxx.ng.0001.use1.cache.amazonaws.com -p 6379

# Set a key
SET user:1001 '{"name":"Alice","age":30}'

# Get a key
GET user:1001

# Use a hash
HSET user:1001 name "Alice" age 30
HGETALL user:1001

# Check info
INFO

#### Memcached CLI examples (using telnet or netcat):

# Connect
telnet mycache.xxxxxx.cfg.use1.cache.amazonaws.com 11211

# Set a key
set user:1001 0 3600 32
{"name":"Alice","age":30}

# Get a key
get user:1001

# Stats
stats

Walk-Through

1

Identify Caching Requirements

Begin by analyzing the application's data access patterns. Determine if you need persistence, complex data structures (e.g., sorted sets for leaderboards), or high availability with automatic failover. Also assess the acceptable latency and throughput. For simple key-value caching without durability, Memcached may suffice. For advanced features, Redis is required. This step guides the engine choice.

2

Choose Engine and Instance Type

Based on requirements, select Redis or Memcached. For Redis, decide between Cluster Mode (for sharding) and non-cluster (for replication). Choose an appropriate node type (e.g., cache.r6g.large for memory-optimized, cache.m6g.large for general purpose). Consider memory overhead: Redis uses more memory per key due to data structures. For Memcached, pick a node type that fits the expected dataset size.

3

Configure Security and Networking

Create the ElastiCache cluster in a VPC. ElastiCache nodes cannot be accessed from outside the VPC without a proxy or VPN. Use security groups to restrict access to only application servers. Enable encryption at rest (using KMS) and in transit (TLS) if required. For Redis, enable AUTH token or RBAC for authentication. For Memcached, consider SASL authentication.

4

Set Up Parameter Groups

Customize parameter groups to tune engine behavior. For Redis, you can modify eviction policy (e.g., allkeys-lru), AOF persistence settings (appendfsync), and reserved-memory (to prevent out-of-memory errors). For Memcached, you can adjust max-item-size (default 1 MB) and max-reqs-per-event. Incorrect parameters can lead to poor performance or data loss.

5

Implement Application Integration

Integrate the cache into your application using SDKs or libraries. Use lazy loading (cache-aside pattern): check cache first, if miss, fetch from database and store in cache. For Redis, consider using Redis client libraries like ioredis (Node.js), redis-py (Python), or Jedis (Java). For Memcached, use libraries like pymemcache or spymemcached. Set appropriate TTLs to avoid stale data.

6

Monitor and Optimize

Use CloudWatch metrics to monitor cache hit ratio, evictions, and CPU usage. A low hit ratio indicates the cache is not effective; consider adjusting TTLs or warming the cache. High evictions indicate memory pressure; scale up or add nodes. For Redis, monitor replication lag to ensure replicas are up to date. For Memcached, monitor slab rebalancing to avoid memory fragmentation.

What This Looks Like on the Job

Enterprise Scenario 1: Session Store for an E-Commerce Platform

A large e-commerce platform uses ElastiCache for Redis to store user session data. The application runs across multiple EC2 instances behind an Application Load Balancer. Sessions are stored as Redis hashes with fields like cart_items, login_token, and preferences. Redis’s persistence (AOF) is enabled to avoid session loss during maintenance. Multi-AZ replication ensures that if the primary node fails, a replica is promoted with minimal downtime. The cluster uses Cluster Mode with 4 shards to handle millions of concurrent sessions. Without Redis, sessions would be lost on server failures, causing users to log in again and lose cart contents.

Enterprise Scenario 2: Database Query Cache for a Reporting Dashboard

A financial analytics company caches expensive SQL query results in ElastiCache for Memcached. The dashboard runs complex aggregations on Amazon RDS for MySQL. Caching reduces database load by 80%. Memcached is chosen because the data is ephemeral (TTL of 5 minutes) and does not require persistence or complex data structures. The cluster has 10 nodes with consistent hashing to distribute keys. If a node fails, the data is reloaded from the database on the next request. The multi-threaded nature of Memcached handles high throughput of cache get/set operations from multiple dashboard servers. Misconfiguration would include setting TTL too long, resulting in stale data, or too short, reducing cache effectiveness.

Enterprise Scenario 3: Real-Time Leaderboard for a Gaming Application

A mobile game uses ElastiCache for Redis with sorted sets to maintain a global leaderboard. Player scores are updated using ZINCRBY commands. Redis’s sorted set operations allow efficient retrieval of top players (ZREVRANGE). The cluster uses Cluster Mode with 2 shards to scale. Persistence is disabled because leaderboard data can be rebuilt from game events. If Redis were not used, the leaderboard would require frequent database writes and reads, increasing latency. A common mistake is using Memcached for this use case, which lacks sorted set support, forcing application-side sorting and increasing complexity.

How SAA-C03 Actually Tests This

SAA-C03 Exam Focus on ElastiCache

The SAA-C03 exam tests your ability to choose between Redis and Memcached based on specific requirements. Key objectives include: - Domain 1: Design Resilient Architectures – Objective 1.2: Design scalable and loosely coupled systems (using ElastiCache for caching). - Domain 2: Design High-Performing Architectures – Objective 2.2: Choose appropriate compute and storage services (ElastiCache as in-memory cache). - Domain 3: Design Secure Applications and Architectures – Objective 3.1: Use encryption and authentication mechanisms.

Common Wrong Answers and Why They Are Wrong

1.

Choosing Memcached for session state because it's simpler. Wrong: Sessions require persistence and high availability; Redis supports replication and persistence. Memcached loses data on node failure.

2.

Choosing Redis for simple key-value caching because it's more feature-rich. Wrong: Memcached is more cost-effective and multi-threaded for simple caching. Redis overhead may be unnecessary.

3.

Enabling persistence on Memcached. Wrong: Memcached does not support persistence; data is always ephemeral.

4.

Assuming Redis Cluster Mode is required for replication. Wrong: Replication (read replicas) is available in non-cluster mode. Cluster mode is for sharding.

Specific Numbers and Terms to Know

Memcached max item size: 1 MB.

Redis max number of read replicas per primary: 5.

Redis Cluster max shards: 500 (ElastiCache limit).

Memcached max nodes per cluster: 20 (soft limit).

Default eviction policy for Redis: volatile-lru.

Eviction policy for Memcached: LRU per slab class.

Ports: Redis 6379, Memcached 11211.

Edge Cases and Exceptions

Redis with Cluster Mode disabled: You can still have up to 5 read replicas for high availability but no sharding.

Memcached auto-discovery: Clients automatically discover all nodes; no need for manual configuration.

Encryption: Both support encryption at rest (KMS) and in transit (TLS). Redis also supports AUTH and RBAC.

Cost: Memcached is generally cheaper per GB because it has less overhead. Redis with persistence and replication costs more.

How to Eliminate Wrong Answers

If the question mentions persistence, replication, complex data structures (lists, sets, sorted sets), atomic operations, or pub/sub, eliminate Memcached.

If the question mentions multi-threaded, simple key-value, lowest cost, ephemeral data, or high throughput for small objects, eliminate Redis.

If the question requires automatic failover, look for Redis with Multi-AZ.

If the question requires horizontal scaling for writes, look for Redis Cluster (sharding).

Key Takeaways

Memcached max item size is 1 MB; larger objects require Redis or splitting.

Redis default eviction policy is volatile-lru; Memcached uses LRU per slab class.

Redis supports up to 5 read replicas per primary; Memcached has no replication.

Redis Cluster mode enables sharding across up to 500 shards for horizontal scaling.

Memcached is multi-threaded; Redis is single-threaded for command execution.

Use Redis for session state, leaderboards, and real-time analytics requiring complex data structures.

Use Memcached for simple, ephemeral caching with high throughput and low cost.

ElastiCache nodes must be in a VPC; access from outside requires a proxy or VPN.

Enable encryption at rest (KMS) and in transit (TLS) for sensitive data.

Monitor cache hit ratio; a low ratio indicates cache inefficiency.

Easy to Mix Up

These come up on the exam all the time. Here's how to tell them apart.

Redis

Supports complex data structures: strings, hashes, lists, sets, sorted sets, bitmaps, etc.

Optional persistence via RDB snapshots or AOF logs.

Supports replication with up to 5 read replicas and Multi-AZ failover.

Single-threaded for command execution; multi-threaded for I/O and background tasks.

Supports transactions, Lua scripting, pub/sub, and geospatial indexing.

Memcached

Only supports simple key-value pairs with string values up to 1 MB.

No persistence; data is lost on restart or failure.

No replication or failover; data is distributed via consistent hashing.

Multi-threaded, utilizing multiple CPU cores for high throughput.

Simpler; no transactions, scripting, or advanced data structures.

Watch Out for These

Mistake

Memcached supports data persistence if configured.

Correct

Memcached is purely in-memory and does not support any form of persistence. Data is lost on node restart or failure. Redis is the only option for persistence.

Mistake

Redis is always faster than Memcached.

Correct

For simple get/set operations with many small objects, Memcached's multi-threaded architecture can outperform Redis's single-threaded event loop, especially on multi-core CPUs.

Mistake

Redis Cluster mode is required for replication.

Correct

Replication (read replicas) is available in both Cluster and non-Cluster modes. Cluster mode is specifically for sharding data across multiple primaries.

Mistake

Memcached can store values larger than 1 MB.

Correct

The maximum item size in Memcached is 1 MB. Larger values must be stored in Redis or split into chunks.

Mistake

ElastiCache for Redis can be used as a primary database.

Correct

While Redis offers persistence, ElastiCache is designed as a cache layer. For production, use RDS or DynamoDB as the primary database; Redis is for caching.

Do You Actually Know This?

Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.

Frequently Asked Questions

Can I use ElastiCache for Redis as a primary database?

Technically yes, but it is not recommended for production. Redis is designed as an in-memory cache with optional persistence. ElastiCache for Redis is best used as a caching layer to offload your primary database (RDS, DynamoDB). For durability and disaster recovery, use a purpose-built database.

What is the difference between Redis Cluster and replication?

Replication creates copies of data on read replicas for high availability and read scaling. Redis Cluster (sharding) partitions data across multiple primaries to handle larger datasets and write scaling. You can combine both: each shard in a cluster can have replicas.

How does Memcached handle node failures?

Memcached has no built-in replication. When a node fails, the data on that node is lost. Clients using consistent hashing will redistribute requests to remaining nodes. The application must reload the cache from the source database on cache misses.

Can I encrypt data in ElastiCache?

Yes, both Redis and Memcached support encryption at rest using AWS KMS and encryption in transit using TLS. Redis also supports AUTH and RBAC for authentication and access control.

What is the maximum number of nodes in an ElastiCache for Memcached cluster?

The default limit is 20 nodes per cluster, but you can request a limit increase via AWS Support. There is no hard limit in the service.

Why would I choose Memcached over Redis for caching?

Memcached is simpler and often cheaper for basic key-value caching. It is multi-threaded, providing higher throughput for many small objects. If you do not need persistence, replication, or complex data types, Memcached is a cost-effective choice.

How do I choose between Redis Cluster and non-cluster?

Use Redis Cluster when you need to scale writes beyond a single node or your dataset exceeds the memory of a single node. Non-cluster mode is sufficient for read-heavy workloads with replication and Multi-AZ failover.

Terms Worth Knowing

Ready to put this to the test?

You've just covered Amazon ElastiCache: Redis vs Memcached — now see how well it sticks with free SAA-C03 practice questions. Full explanations included, no account needed.

Done with this chapter?