6.71 ELASTICACHE overview
ElastiCache is to caching what RDS is to relational databases: a managed service that handles your in-memory cache. With Redis or Memcached, data is held in RAM, which delivers very low latency and high throughput. ElastiCache reduces the workload on your databases for read-heavy traffic by caching frequent queries. It also improves write availability through sharding (spreading data across multiple machines) and scales read traffic horizontally with read-only replicas. Adding more resources lets your applications stay decoupled, since each one fetches data from a shared cache instead of hitting the database directly.
ElastiCache can run across multiple Availability Zones and Regions with failover capabilities. AWS handles the full operational burden: patching, configuration tuning, monitoring, recovery on failure and backups. If your cache crashes, AWS restores it to a state close to the moment of failure. Using a cache requires changes in your application code so it knows when to talk to ElastiCache and when to talk to the database — we will see this in the lab.
Two common usage patterns
- Read-heavy cache in front of RDS: the app first queries ElastiCache; on a hit, RDS is never contacted. On a miss, the app reads from RDS, writes the result into the cache and returns it. A cache invalidation strategy is required to keep data fresh.
- User session store: when the app runs behind an Auto Scaling group, sessions are written to ElastiCache. If a user is routed to another instance, that instance retrieves the session from the cache and recognises the user as already logged in.
Redis and Memcached differ in capabilities. Redis supports Multi-AZ deployment with failover, read replicas for high availability, data durability via AOF (Append-Only File) persistence, and backup and restore in AWS — making it close to a database in resilience. Memcached uses multiple nodes to shard data, has no persistence, no backup or restore, and a multi-threaded architecture. It fits use cases where you split data across several caches by business logic, for example users from one year on one node and users from another year on a different node.
Summary
AWS ElastiCache is a managed caching service that stores frequently accessed data in memory (using Redis or Memcached engines), dramatically improving application performance and reducing the load on relational databases like RDS. It enables read-intensive workloads to be served with extremely low latency, and supports both Redis (with persistence and read replicas) and Memcached (with multi-node sharding for horizontal scaling). ElastiCache also stores user sessions across multiple application instances, ensuring seamless user experience in load-balanced environments.
Key points
- ElastiCache reduces database read load by caching frequently accessed data in memory with low latency, improving overall application performance
- Supports two engines: Redis (with persistence via AOF snapshots and read replicas for high availability) and Memcached (with multi-node sharding for horizontal scaling)
- Enables efficient session storage across multiple application instances, allowing users to maintain their session state regardless of which instance they connect to
- Cache invalidation strategies must be implemented to ensure only current data is delivered to users and prevent stale information
- AWS manages all infrastructure maintenance, patching, optimization, monitoring, and automatic failover recovery for uninterrupted service
- Improves high availability and enables horizontal read scaling through replication and multi-zone/multi-region deployment
FAQ
How does ElastiCache improve database performance?
ElastiCache caches frequently accessed data in memory. When an application queries the cache, it receives the response directly without hitting the database, reducing the load on RDS and providing responses with minimal latency. If data is not in the cache, the application fetches it from the database, stores it in the cache, and serves subsequent requests from the cache.
What is the difference between Redis and Memcached in ElastiCache?
Redis supports data persistence (AOF and snapshots), read replicas for high availability, and write sharding for data replication across multiple machines. Memcached uses multi-node sharding to distribute data across multiple nodes without persistence, backup/restore functionality, or read replication capabilities.
How can ElastiCache store user sessions in a load-balanced environment?
ElastiCache stores user session data in the cache when a user logs in through any application instance. When the same user connects to a different instance, that instance retrieves the session data directly from the cache, eliminating the need to re-authenticate and ensuring a seamless experience across all application instances.