Amazon ElastiCache is a managed in-memory caching service for Redis and Memcached. A caching layer can reduce response latency and lower pressure on a primary data store. section 11.7 section 1.6
Choose the engine according to the data and scaling features required:
- Memcached provides a simple key-value store and can scale memory and throughput by adding shards. section 11.7
- Redis supports richer structures such as sorted sets, making it suitable for sessions, leaderboards, and other application data. section 11.1.2 section 11.7
- Cache entries commonly expire after a period, use a write-through strategy, or are evicted when the cache fills. section 11.7
Applications reach ElastiCache through a network path, usually from a virtual machine in the same VPC. IAM controls cluster administration, security groups control node traffic, and the engine controls data access. Redis supports token authentication or role-based access control; Memcached does not provide user authentication. Enable encryption in transit when authentication secrets are used. section 11.3 section 11.3.3
Store a session and build a leaderboard
After creating a minimal Redis cluster and connecting through an EC2 instance with Redis CLI, set a session with a 15-second expiry: SET session:gamer1 online EX 15. GET returns online before expiry and (nil) afterward. Add scores with ZADD highscore 100 gamer1 and read the ordered results with ZRANGE highscore -3 -1 WITHSCORES. Delete the CloudFormation stack when finished. section 11.1.2
A CloudFormation deployment can define a cache subnet group, a cache security group, and a Redis cache cluster, allowing only application instances to reach port 6379. A single node is a minimal configuration; additional nodes, read replicas, or sharding address availability, read capacity, or memory requirements. section 11.1.2 section 11.6
Use the performance decision tree to choose between a larger node, horizontal deployment, or data compression when CPU, memory, or network usage makes the cache a bottleneck. section 11.6

