SlideShare a Scribd company logo
1 of 47
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Dan Zamansky, Senior Product Manager
May 26, 2016
AWS Webinar Series
Integrating Amazon ElastiCache into
Your Database Stack
Learning Objectives
• Understand key Amazon ElastiCache features
• Learn how to set up Amazon ElastiCache and how to integrate it into
your database stack
• Explore sample use cases, best practices, and tips on using Amazon
ElastiCache to speed up your application by reducing database
latencies and increasing throughput
Modern Applications Require Real-Time
Performance
We live in a connected world (IoT)
• Phones, Tablets, Cars, Air Conditioners, Toasters
Experiences are increasingly contextual
Apps need to provide real-time responses
Database performance is frequently the bottleneck
Load is spikey and unpredictable
Businesses Need To Be Ready For Success!
What is ElastiCache?
AWS Database Services
Compute Storage
AWS Global Infrastructure
Database
Application Services
Deployment & Administration
Networking
Performance Optimized In-Memory
Key-Value Store in the Cloud
Amazon RDS
Amazon DynamoDB Amazon Redshift
Amazon ElastiCache
Fully managed service = Automated Operations
In-Memory datastore self-hosted on
Amazon EC2
Amazon ElastiCache
In-Memory Key-Value Store
High-performance
Redis and Memcached
Fully managed; Zero admin
Highly Available and Reliable
Hardened by Amazon
Amazon
ElastiCache
Amazon
RDS
Amazon S3
Request Rate
High Low
Latency
Low High
Data Volume
Low High
Amazon
Glacier
Amazon
CloudSearch
Structure
Low
High
Amazon
DynamoDB
Amazon
ElastiCache
HDFS
ElastiCache - Customer Value
Extreme
Performance
Sub-millisecond
access latencies
Engineered for
Cloud Scale
Open Source
Compatible
Compatible with
Redis and
Memcached
Existing code will
work when you
update node end
points
Fully Managed
Automates tasks
such as failed node
replacement,
software patching,
upgrades and
backups
CloudWatch
enables you to
monitor cache
performance
metrics
Secure and
Hardened
Supports Amazon
VPC and IAM for
secure and fine
grained access.
Monitors your
nodes and applies
security patches
when necessary
Highly
Available and
Scalable
Multi-AZ with
automatic failover to
a read replica, no
human intervention
required.
Easily scale your
Redis (vertically)
and Memcached
(horizontally)
environments
Cost Effective
Pay as low as 17
cents per hour. Get
started with 750
free hours per
month of a micro
node for a year.
No cross availability
zone data transfer
costs.
Memcached
Slab allocator
In-memory key-value datastore
very popular as a caching solution
Supports strings, objects
Multi-threaded
Insanely fast!
Very established
No persistence
Patterns for sharding
Redis – the in-memory king
Powerful
~200 commands
In-memory data structure server
Utility data structures
strings, lists, hashes, sets, sorted sets,
bitmaps & HyperLogLogs
Simple
Atomic operations
supports transactions
has ACID properties
Ridiculously fast!
<1ms latency for most commands
Highly Available
Persistent
snapshots or append-only log
Open Source
Why Memcached and Redis?
Source: http://db-engines.com/en/ranking/key-value+store
Deploying ElastiCache for
ElastiCache with Redis - Development
Region
Availability Zone A Availability Zone B
Auto Scaling group
ElastiCache cluster
Nope
Primary
Availability Zone A Availability Zone B
Replica
Replica
writes
Use Primary Endpoint
reads
Use Read Replicas
Auto-Failover
 Chooses replica with
lowest replication lag
 DNS endpoint is same
ElastiCache for Redis Multi-AZ
ElastiCache
for Redis
ElastiCache
for Redis
ElastiCache
for Redis
Automatic Failover to a read replica in case of
primary node failure
ElastiCache
Automates
snapshots for
persistence
ElastiCache with Redis Multi-AZ
Region
Availability Zone A Availability Zone B
Auto Scaling group
ElastiCache cluster
ElastiCache with Redis Multi-AZ
Region
Availability Zone A Availability Zone B
Auto Scaling group
ElastiCache cluster
ElastiCache with Redis Multi-AZ
Region
Availability Zone A Availability Zone B
Auto Scaling group
ElastiCache cluster
ElastiCache with Redis Multi-AZ
Region
Availability Zone A Availability Zone B
Auto Scaling group
ElastiCache cluster
Redis – Read/Write Connections
Create Snapshot
Restore Snapshot
Restore Snapshot
Key Use Patterns
Use Case #1 - Caching
Elastic Load
Balancing
EC2 App
Instances
RDS MySQL
DB Instance
ElastiCache
Database Writes
App
Reads
Clients
Cache
Updates
Database Reads
Amazon
ElastiCache
Eliminate database hotspots
Predictable Performance
Cut Load on Backend
Increase Read Throughput
Reduce App Latency
Caching Will Make Your Database More Efficient
Reduce Database Cost
Common Caching Technique #1 – Lazy Caching:
Adding Caching to Your Application is Easy
Common Caching Technique #2 – Write-back caching:
Adding Caching to Your Application is Easy
Not if I
destroy it
first!
It’s
mine!
Very popular for gaming apps
Need uniqueness + ordering
Easy with Redis Sorted Sets
ZADD "leaderboard" 1201 "Gollum”
ZADD "leaderboard" 963 "Sauron"
ZADD "leaderboard" 1092 "Bilbo"
ZADD "leaderboard" 1383 "Frodo”
ZREVRANGE "leaderboard" 0 -1
1) "Frodo"
2) "Gollum"
3) "Bilbo"
4) "Sauron”
ZREVRANK "leaderboard" "Sauron"
(integer) 3
Use Case 2 - Real-time Leaderboard
Use Case 3 - Chat and Messaging
• PUBLISH and SUBSCRIBE Redis commands
• Game or Mobile chat, real-time comment streams
• Server intercommunication
SUBSCRIBE chat_channel:114
PUBLISH chat_channel:114 "Hello all"
>> ["message", "chat_channel:114", "Hello all"]
UNSUBSCRIBE chat_channel:114
• Popular for recommendation engines and message board ranking
• Redis counters – increment likes/dislikes
• Redis hashes – list of everyone’s ratings
• Process with algorithm like Slope One or Jaccardian similarity
• Ruby example - https://github.com/davidcelis/recommendable
Use Case 4 – Ratings
INCR item:38927:likes
HSET item:38927:ratings "Susan" 1
INCR item:38927:dislikes
HSET item:38927:ratings "Tommy" -1
Ex: Throttling requests to an API
Leverages Redis Counters
ELB
Externally
Facing
API
Reference: http://redis.io/commands/INCR
FUNCTION LIMIT_API_CALL(APIaccesskey)
limit = HGET(APIaccesskey, “limit”)
time = CURRENT_UNIX_TIME()
keyname = APIaccesskey + ":” + time
count = GET(keyname)
IF current != NULL && count > limit THEN
ERROR ”API request limit exceeded"
ELSE
MULTI
INCR(keyname)
EXPIRE(keyname,10)
EXEC
PERFORM_API_CALL()
END
Use Case 5 - Rate Limiting
Tune It Up!
Alarms
Monitoring with CloudWatch
• Easily Accessible via the
ElastiCache console
• Track health of your
nodes
• Set alarms to act when
need to address running
into limitations
Key ElastiCache CloudWatch Metrics
• CPUUtilization
• Memcached – up to 90% ok
• Redis – divide by cores (ex: 90% / 4 = 22.5%)
• SwapUsage low
• Evictions low
• CacheMisses / CacheHits Ratio low
• CurrConnections stable
Common Issues
Thundering Herd
Causes
• Cold cache – app startup
• Adding / removing nodes
• Cache key expiration (TTL)
• Out of cache memory
Large # of cache misses 
Spike in database load
Mitigations
• Script to populate cache
• Gradually scale nodes
• Randomize TTL values
• Monitor cache evictions
1. Forks main Redis process
2. Writes backup to disk from child process
3. Continues to accept traffic on main process
4. Any key update causes a copy-on-write
5. Potentially DOUBLES memory usage by Redis
Swapping During Redis Backup (BGSAVE)
Reduce memory allocated to Redis
• Set reserved-memory field in parameter groups
• Decreases node memory available for app
Use larger cache node type
• More expensive
• But no data eviction
Write-heavy apps need extra memory
http://bit.ly/elasticache-bgsave
Swapping During Redis Backup – Mitigations
Redis reserved-memory Parameter
Recap
• In-memory data store can help address the most demanding application
requirements, as well as protect from impact of spikes in app access.
• ElastiCache is a reliable, secure and fully-managed, performance-optimized
in-memory data structure service.
• Use Multi-AZ with automatic failover for production workloads.
• Redis provides powerful capabilities for a variety of in-memory use cases
• For much more detail on setting up and using ElastiCache please see our
whitepaper (google “ElastiCache whitepaper”)
Free tier: 750 hours of Micro Cache Node per Month
Pay as little as $0.017 per hour thereafter
for a T2.micro node
You can get started for free
Thank you!

More Related Content

Viewers also liked

Viewers also liked (10)

February 2016 Webinar Series - Introducing VPC Support for AWS Lambda
February 2016 Webinar Series - Introducing VPC Support for AWS LambdaFebruary 2016 Webinar Series - Introducing VPC Support for AWS Lambda
February 2016 Webinar Series - Introducing VPC Support for AWS Lambda
 
Redis Labs and SQL Server
Redis Labs and SQL ServerRedis Labs and SQL Server
Redis Labs and SQL Server
 
Managing Your Application Lifecycle on AWS: Continuous Integration and Deploy...
Managing Your Application Lifecycle on AWS: Continuous Integration and Deploy...Managing Your Application Lifecycle on AWS: Continuous Integration and Deploy...
Managing Your Application Lifecycle on AWS: Continuous Integration and Deploy...
 
CMS on AWS Deep Dive
CMS on AWS Deep DiveCMS on AWS Deep Dive
CMS on AWS Deep Dive
 
雲端媒體串流
雲端媒體串流雲端媒體串流
雲端媒體串流
 
Architecting an Highly Available and Scalable WordPress Site in AWS
Architecting an Highly Available and Scalable WordPress Site in AWS Architecting an Highly Available and Scalable WordPress Site in AWS
Architecting an Highly Available and Scalable WordPress Site in AWS
 
React JS and why it's awesome
React JS and why it's awesomeReact JS and why it's awesome
React JS and why it's awesome
 
AWS Webinar-Introducing Amazon ElastiCache for Redis
AWS Webinar-Introducing Amazon ElastiCache for RedisAWS Webinar-Introducing Amazon ElastiCache for Redis
AWS Webinar-Introducing Amazon ElastiCache for Redis
 
Getting Started with Amazon ElastiCache
Getting Started with Amazon ElastiCacheGetting Started with Amazon ElastiCache
Getting Started with Amazon ElastiCache
 
AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Effi...
AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Effi...AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Effi...
AWS re:Invent 2016: Running Lean Architectures: How to Optimize for Cost Effi...
 

More from Amazon Web Services

Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWS
Amazon Web Services
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch Deck
Amazon Web Services
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
Amazon Web Services
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
Amazon Web Services
 

More from Amazon Web Services (20)

Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
 
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
 
Esegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS FargateEsegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS Fargate
 
Costruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWSCostruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWS
 
Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot
 
Open banking as a service
Open banking as a serviceOpen banking as a service
Open banking as a service
 
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
 
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
 
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows WorkloadsMicrosoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
 
Computer Vision con AWS
Computer Vision con AWSComputer Vision con AWS
Computer Vision con AWS
 
Database Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatareDatabase Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatare
 
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJSCrea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
 
API moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e webAPI moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e web
 
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatareDatabase Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
 
Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWS
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch Deck
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
 
Fundraising Essentials
Fundraising EssentialsFundraising Essentials
Fundraising Essentials
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
 
Introduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceIntroduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container Service
 

Recently uploaded

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 

Integrating Amazon ElastiCache into Your Database Stack - AWS May 2016 Webinar Series

  • 1. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Dan Zamansky, Senior Product Manager May 26, 2016 AWS Webinar Series Integrating Amazon ElastiCache into Your Database Stack
  • 2. Learning Objectives • Understand key Amazon ElastiCache features • Learn how to set up Amazon ElastiCache and how to integrate it into your database stack • Explore sample use cases, best practices, and tips on using Amazon ElastiCache to speed up your application by reducing database latencies and increasing throughput
  • 3. Modern Applications Require Real-Time Performance We live in a connected world (IoT) • Phones, Tablets, Cars, Air Conditioners, Toasters Experiences are increasingly contextual Apps need to provide real-time responses Database performance is frequently the bottleneck Load is spikey and unpredictable
  • 4. Businesses Need To Be Ready For Success!
  • 6. AWS Database Services Compute Storage AWS Global Infrastructure Database Application Services Deployment & Administration Networking Performance Optimized In-Memory Key-Value Store in the Cloud Amazon RDS Amazon DynamoDB Amazon Redshift Amazon ElastiCache
  • 7. Fully managed service = Automated Operations In-Memory datastore self-hosted on Amazon EC2 Amazon ElastiCache
  • 8. In-Memory Key-Value Store High-performance Redis and Memcached Fully managed; Zero admin Highly Available and Reliable Hardened by Amazon Amazon ElastiCache
  • 9. Amazon RDS Amazon S3 Request Rate High Low Latency Low High Data Volume Low High Amazon Glacier Amazon CloudSearch Structure Low High Amazon DynamoDB Amazon ElastiCache HDFS
  • 10. ElastiCache - Customer Value Extreme Performance Sub-millisecond access latencies Engineered for Cloud Scale Open Source Compatible Compatible with Redis and Memcached Existing code will work when you update node end points Fully Managed Automates tasks such as failed node replacement, software patching, upgrades and backups CloudWatch enables you to monitor cache performance metrics Secure and Hardened Supports Amazon VPC and IAM for secure and fine grained access. Monitors your nodes and applies security patches when necessary Highly Available and Scalable Multi-AZ with automatic failover to a read replica, no human intervention required. Easily scale your Redis (vertically) and Memcached (horizontally) environments Cost Effective Pay as low as 17 cents per hour. Get started with 750 free hours per month of a micro node for a year. No cross availability zone data transfer costs.
  • 11. Memcached Slab allocator In-memory key-value datastore very popular as a caching solution Supports strings, objects Multi-threaded Insanely fast! Very established No persistence Patterns for sharding
  • 12. Redis – the in-memory king Powerful ~200 commands In-memory data structure server Utility data structures strings, lists, hashes, sets, sorted sets, bitmaps & HyperLogLogs Simple Atomic operations supports transactions has ACID properties Ridiculously fast! <1ms latency for most commands Highly Available Persistent snapshots or append-only log Open Source
  • 13. Why Memcached and Redis? Source: http://db-engines.com/en/ranking/key-value+store
  • 15. ElastiCache with Redis - Development Region Availability Zone A Availability Zone B Auto Scaling group ElastiCache cluster Nope
  • 16. Primary Availability Zone A Availability Zone B Replica Replica writes Use Primary Endpoint reads Use Read Replicas Auto-Failover  Chooses replica with lowest replication lag  DNS endpoint is same ElastiCache for Redis Multi-AZ ElastiCache for Redis ElastiCache for Redis ElastiCache for Redis Automatic Failover to a read replica in case of primary node failure ElastiCache Automates snapshots for persistence
  • 17. ElastiCache with Redis Multi-AZ Region Availability Zone A Availability Zone B Auto Scaling group ElastiCache cluster
  • 18. ElastiCache with Redis Multi-AZ Region Availability Zone A Availability Zone B Auto Scaling group ElastiCache cluster
  • 19. ElastiCache with Redis Multi-AZ Region Availability Zone A Availability Zone B Auto Scaling group ElastiCache cluster
  • 20. ElastiCache with Redis Multi-AZ Region Availability Zone A Availability Zone B Auto Scaling group ElastiCache cluster
  • 21.
  • 22.
  • 23.
  • 24. Redis – Read/Write Connections
  • 29. Use Case #1 - Caching Elastic Load Balancing EC2 App Instances RDS MySQL DB Instance ElastiCache Database Writes App Reads Clients Cache Updates Database Reads
  • 30. Amazon ElastiCache Eliminate database hotspots Predictable Performance Cut Load on Backend Increase Read Throughput Reduce App Latency Caching Will Make Your Database More Efficient Reduce Database Cost
  • 31. Common Caching Technique #1 – Lazy Caching: Adding Caching to Your Application is Easy
  • 32. Common Caching Technique #2 – Write-back caching: Adding Caching to Your Application is Easy
  • 33. Not if I destroy it first! It’s mine! Very popular for gaming apps Need uniqueness + ordering Easy with Redis Sorted Sets ZADD "leaderboard" 1201 "Gollum” ZADD "leaderboard" 963 "Sauron" ZADD "leaderboard" 1092 "Bilbo" ZADD "leaderboard" 1383 "Frodo” ZREVRANGE "leaderboard" 0 -1 1) "Frodo" 2) "Gollum" 3) "Bilbo" 4) "Sauron” ZREVRANK "leaderboard" "Sauron" (integer) 3 Use Case 2 - Real-time Leaderboard
  • 34. Use Case 3 - Chat and Messaging • PUBLISH and SUBSCRIBE Redis commands • Game or Mobile chat, real-time comment streams • Server intercommunication SUBSCRIBE chat_channel:114 PUBLISH chat_channel:114 "Hello all" >> ["message", "chat_channel:114", "Hello all"] UNSUBSCRIBE chat_channel:114
  • 35. • Popular for recommendation engines and message board ranking • Redis counters – increment likes/dislikes • Redis hashes – list of everyone’s ratings • Process with algorithm like Slope One or Jaccardian similarity • Ruby example - https://github.com/davidcelis/recommendable Use Case 4 – Ratings INCR item:38927:likes HSET item:38927:ratings "Susan" 1 INCR item:38927:dislikes HSET item:38927:ratings "Tommy" -1
  • 36. Ex: Throttling requests to an API Leverages Redis Counters ELB Externally Facing API Reference: http://redis.io/commands/INCR FUNCTION LIMIT_API_CALL(APIaccesskey) limit = HGET(APIaccesskey, “limit”) time = CURRENT_UNIX_TIME() keyname = APIaccesskey + ":” + time count = GET(keyname) IF current != NULL && count > limit THEN ERROR ”API request limit exceeded" ELSE MULTI INCR(keyname) EXPIRE(keyname,10) EXEC PERFORM_API_CALL() END Use Case 5 - Rate Limiting
  • 38. Alarms Monitoring with CloudWatch • Easily Accessible via the ElastiCache console • Track health of your nodes • Set alarms to act when need to address running into limitations
  • 39. Key ElastiCache CloudWatch Metrics • CPUUtilization • Memcached – up to 90% ok • Redis – divide by cores (ex: 90% / 4 = 22.5%) • SwapUsage low • Evictions low • CacheMisses / CacheHits Ratio low • CurrConnections stable
  • 41. Thundering Herd Causes • Cold cache – app startup • Adding / removing nodes • Cache key expiration (TTL) • Out of cache memory Large # of cache misses  Spike in database load Mitigations • Script to populate cache • Gradually scale nodes • Randomize TTL values • Monitor cache evictions
  • 42. 1. Forks main Redis process 2. Writes backup to disk from child process 3. Continues to accept traffic on main process 4. Any key update causes a copy-on-write 5. Potentially DOUBLES memory usage by Redis Swapping During Redis Backup (BGSAVE)
  • 43. Reduce memory allocated to Redis • Set reserved-memory field in parameter groups • Decreases node memory available for app Use larger cache node type • More expensive • But no data eviction Write-heavy apps need extra memory http://bit.ly/elasticache-bgsave Swapping During Redis Backup – Mitigations
  • 45. Recap • In-memory data store can help address the most demanding application requirements, as well as protect from impact of spikes in app access. • ElastiCache is a reliable, secure and fully-managed, performance-optimized in-memory data structure service. • Use Multi-AZ with automatic failover for production workloads. • Redis provides powerful capabilities for a variety of in-memory use cases • For much more detail on setting up and using ElastiCache please see our whitepaper (google “ElastiCache whitepaper”)
  • 46. Free tier: 750 hours of Micro Cache Node per Month Pay as little as $0.017 per hour thereafter for a T2.micro node You can get started for free