0PricingLogin
AWS Solutions Architect · Lesson

ElastiCache Redis Replication Groups and Cluster Mode

Build a Redis replication group for read scaling and enable cluster mode to shard data across multiple node groups.

Redis Replication Groups Overview

An ElastiCache Replication Group is a logical grouping of one primary Redis node and up to 5 read replicas. The primary node handles all write operations; replicas receive asynchronous replication from the primary and serve read traffic. Replication groups enable two key capabilities: read scaling (distribute read requests across multiple replicas) and high availability with automatic failover (promote a replica to primary if the primary fails). All nodes in a replication group share the same dataset.

# Create a replication group with 1 primary and 2 read replicas
aws elasticache create-replication-group \
  --replication-group-id web-cache \
  --replication-group-description 'Web application cache' \
  --num-cache-clusters 3 \
  --cache-node-type cache.r7g.large \
  --engine redis \
  --engine-version '7.0' \
  --automatic-failover-enabled \
  --multi-az-enabled \
  --cache-subnet-group-name my-multi-az-subnet-group

Primary Endpoint vs Reader Endpoint

ElastiCache provides two DNS endpoints for a replication group: the primary endpoint always points to the current primary node (automatically updated during failover) — use this for all write operations. The reader endpoint load-balances read requests across all available replicas — use this for read operations to distribute load. Your application should maintain two connection pools: one for the primary endpoint for writes and one for the reader endpoint for reads. This is the recommended connection pattern for ElastiCache Redis replication groups.

# Get primary and reader endpoints
aws elasticache describe-replication-groups \
  --replication-group-id web-cache \
  --query 'ReplicationGroups[].{
    Primary:NodeGroups[].PrimaryEndpoint.Address,
    Reader:ReaderEndpoint.Address
  }'

# Application connection pattern:
# write_client = redis.Redis(host='primary-endpoint', port=6379)
# read_client = redis.Redis(host='reader-endpoint', port=6379)

All lessons in this course

  1. Redis vs Memcached: Choosing the Right Engine
  2. ElastiCache Redis Replication Groups and Cluster Mode
  3. Caching Strategies: Lazy Loading and Write-Through
  4. Session Storage and Leaderboard Patterns
← Back to AWS Solutions Architect