Redis is an in-memory database for fast reads and writes. It can serve as a cache in front of a relational database, reducing database traffic and application latency. Unlike a simple key-value cache, it supports complex data structures such as sorted sets. section 11.0 section 11.7
A game leaderboard
A game can keep its primary records in a relational database while maintaining a working leaderboard in a Redis sorted set. Scores determine the order as entries are inserted; `ZREVRANGE "player-scores" 0 9` retrieves the top ten without sorting millions of records in the primary database. section 11.0
Choose an AWS deployment according to the workload:
- ElastiCache for Redis, single node: supports backup and restore, but not replication or sharding. The node is a single point of failure. section 11.2.2
- ElastiCache for Redis, cluster mode disabled: adds replication but not sharding. Cluster mode enabled adds both. section 11.2
- MemoryDB: offers Redis compatibility, replication, sharding, and stronger persistence guarantees. section 11.2 section 11.7
To provision a single-node ElastiCache cluster with CloudFormation, define an `AWS::ElastiCache::CacheCluster` with `Engine: redis`, a node type, `NumCacheNodes: 1`, a subnet group, and security groups. ElastiCache nodes have private IP addresses; test connectivity from an EC2 instance in the same VPC rather than from the internet. section 11.1.1
Secure management and data access separately. IAM governs cluster administration; security groups govern network traffic. Redis can authenticate clients with a shared token or, in versions above 6.0, use role-based access control to give clients different permissions. Enable in-transit encryption when using authentication so secrets are not sent in plain text. section 11.3 section 11.3.3
A forum cache
Discourse uses PostgreSQL as its main data store and Redis for cached and transient data. A CloudFormation deployment combines the cache, database, networking, and EC2 instance; once running, monitor ElastiCache utilization and performance with CloudWatch. section 11.4 section 11.4.5 section 11.7
A cache still needs a freshness strategy: let entries expire or use write-through updates to keep it aligned with the database. When full, it may evict less-used items. Weigh those behaviors alongside availability, memory capacity, throughput, and persistence requirements before choosing a deployment. section 11.7 section 11.2
Table 11.2 Comparing ElastiCache and MemoryDB engines and deployment options (view table figure)
Compare backup and restore, replication, and sharding across ElastiCache and MemoryDB deployment options. section 11.2





