Performance at Scale with Amazon ElastiCache


  • ElastiCache deploys one or more cache clusters for your application
  • ElastiCache automates resources provisioning, failure detection and recovery, and software patching
  • Supports Redis and Memcached engines

Alternatives to ElastiCache

  • Amazon CloudFront - cache images, web pages, static data at the edge
  • Amazon RDS Read Replicas - distributing data to remote apps
  • On-host caching - this approach lacks of efficiency - cannot reuse existing cache entries and maintain consistency in validation of the cache keys across all hosts

Memcached vs Redis

  • Due to replication and persistence features of Redis, Redis is managed as relational database
  • Memcached is designed as pure caching solution with no persistence - is managed as pool of nodes that can grow and shrink, similar to Amazon EC2 Auto Scaling Group

Important questions to consider impacting the choice of the caching engine:


  • Object caching as a primary goal? Offload database?
  • Simplest caching model?
  • Large cached nodes, multi-threaded performance with utilization of multiple cores
  • Scale cache horizontally?
  • Atomically increment / decrement counters?


  • More advanced types, e.g. lists, hashes, bit arrays, HyperLogLogs and sets?
  • Sorting and ranking datasets in memory?
  • Pub/Sub capabilities in your application?
  • Persistence of the key store?
  • Run in multiple AZs with failover?
  • Geospatial support?
  • Encryption and compliance standards? PCI DSS, HIPAA, FedRAMP?

ElastiCache for Memcached

  • Considerably cheaper to add an in-memory cache then to scale up to a larger database cluster
  • Easier to distribute an in-memory cache horizontally in comparison to relational database
  • Choose the same AZs for ElastiCache as your application servers
    • Specify Preferred Zones option during cache cluster creation
    • Spread Nodes Across Zones tells ElastiCache to distribute nodes to AZs evenly
  • Expect slightly higher latency for cross-zone AZ requests

Cache Node Size

  • M5 or R5 families support the latest generation CPUs and networking capabilities
  • Delivers up to 25Gbps of aggregate networking bandwidth with enhanced networking and over 600 GiB of memory
  • M5.large single node can be a good starting point
  • Track resource utilization through CloudWatch metrics
  • Estimate the memory requirements by calculating the size consumed per cache item x number of items you want to cache

Security Groups and VPC

  • ElastiCache supports security groups
  • Advised to launch in a private subnet with no public connectivity
  • Memcache doesn’t have any serious authentication or encryption capabilities
  • Create a security group for ElastiCache cluster and allow traffic from “application tier” security group
  • Test connectivity from an application instance to your cache cluster in VPC, using netcat:
nc -z w5 [cache endpoint] 11211
# will return 0 if connection was successful (the exist code of last command)
echo $?

Caching Design Patterns