ElastiCache Redis and Memcached

Build on your understanding of AWS ElastiCache by delving into Redis and Memcached.

ElastiCache Redis

ElastiCache can be used to provision managed Redis caches. It also supports Redis in cluster mode.

Points to note:

  • ElastiCache Redis caches automatically detect and recover from cache node failures.
  • Redis isn’t multithreaded.
  • With cluster mode enabled, Redis can partition data in up to 250 shards.
  • Authentication to Redis clusters can be controlled using Redis AUTH.
  • It supports in-flight encryption using SSL.
  • Redis sorted sets allow us to store and order different elements. For example, in a popular exam scenario, we can use Redis sorted sets to maintain a leaderboard without programming this functionality in the application. New elements are ranked and placed in the correct position in real time.
  • We can create two cross-region replica clusters for ElastiCache Redis.
  • As in RDS, we can enable Multi-AZ functionality. This will automatically replace the primary node in a shard with a read replica in case of failover. To use Multi-AZ, a node must have at least one read replica.
  • Backup and restore operations can be used to migrate and resize Redis clusters.
  • ElastiCache can seamlessly scale Redis clusters vertically (changing the node type) while performing routine operations. To scale Redis vertically, ElastiCache creates a new node group (shard), replicates data from the old to the new shard, and updates the DNS to point to the new shard.

Cluster modes

Redis can be used with cluster mode enabled or turned off. When cluster mode is turned off, all the data in the cache is stored in the primary node. The primary node can have up to five read replicas, and in case of a primary node failure, one of the read replicas replaces the primary node. When the cluster mode is turned off, we can only scale the read capacity of Redis by adding read replicas (a maximum of five).

When cluster mode is enabled, data is partitioned between primary nodes. In the illustration below, data is divided into two parts. Partitioning data in a cluster helps scale the write capacity of Redis. When cluster mode is enabled, we can have a maximum of 500 nodes in a cluster, including read replicas. For example:

  • For a cluster with no read replicas, we can have 500 primary nodes.
  • For a cluster with one read replica per primary node, we can have 250 primary nodes with one read replica each for a total of 500 nodes.
  • For a cluster with five read replicas per primary node, we can have 83 primary nodes with five read replicas each for a total of 498 nodes.
  • For a cluster with 10 read replicas per primary node, we can have 45 primary nodes with 10 read replicas each for a total of 495 nodes.

Scaling Redis with cluster mode enabled can be done in two modes:

  • Online scaling: The cluster continues to serve requests with minimal impact on performance. Vertical scaling is always online.
  • Offline scaling: The cluster stops service requests while scaling.

When cluster mode is enabled, we can scale the read-and-write capacity of the cluster by:

  • Resharding: Adding or removing shards.
  • Shard rebalancing: Equally distributing data across shards.

Get hands-on with 1200+ tech skills courses.