SlideShare a Scribd company logo
1 of 70
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Unleash the power of Redis with Amazon
ElastiCache
Michael Labib,
Specialist Solutions Architect
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
What we’ll cover
• ElastiCache Redis Overview
• Common Architecture Patterns
• Best Practices
• Caching Strategies
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
In-Memory Key-Value Store
High-performance
Redis and Memcached
Fully managed; Zero admin
Highly Available and Reliable
Hardened by Amazon
Amazon
ElastiCache
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Request Rate
High Low
Latency
Low High
Structure
Low
High
Data Volume
Low High
Amazon
RDS
Amazon S3
Amazon
Glacier
Amazon
CloudSearch and
Amazon Elasticsearch
Amazon
DynamoDB
Amazon
ElastiCache
and DAX
HDFS
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Redis – The In-Memory Leader
Powerful
~200 commands + Lua scripting
In-memory data structure server
Utility data structures
strings, lists, hashes, sets, sorted sets,
bitmaps & HyperLogLogs
Simple
Atomic operations
supports transactions
Ridiculously fast!
<1ms latency for most commands
Highly Available
replication
Persistence
Open Source
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Redis Data Types & More!
Run Lua scripts Geospatial Queries! Pub / Sub
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Amazon
ElastiCache
Optimized Swap Memory
•Mitigate the risk of increased swap usage
during syncs and snapshots.
Dynamic write throttling
•Improved output buffer management when
the node’s memory is close to being
exhausted.
Smoother failovers
•Clusters recover faster as replicas avoid
flushing their data to do a full re-sync with the
primary.
ElastiCache Engine Enhancements
Enhanced failover quorum logic
When majority primary nodes are missing,
the cluster is still operational
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
ElastiCache Redis Topologies
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
ElastiCache Redis with Multi-AZ
(non-clustered)
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
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
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
ElastiCache with Redis Multi-AZ
Region
Availability Zone A Availability Zone B
ElastiCache Cluster
Auto Scaling
Primary
Read Replica
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
ElastiCache with Redis Multi-AZ
Region
Availability Zone A Availability Zone B
Primary
Read Replica
Auto Scaling
ElastiCache Cluster
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
ElastiCache with Redis Multi-AZ
Region
Availability Zone A Availability Zone B
Primary
Read Replica
Auto Scaling
ElastiCache Cluster
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Scaling with Redis Cluster
(clustered mode enabled)
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Scaling with Redis Cluster
(clustered mode enabled)
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Setting up Redis Cluster - Console
Cluster Mode
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Redis Cluster – Automatic Client-Side Sharding
S5
S1
S2
S4 S3
Client
• 16384 hash slots per Cluster
• Slot for a key is CRC16 modulo {key}
• Slots are distributed across the Cluster
into Shards
• Developers must use a Redis cluster client!
• Clients are redirected to the correct shard
• Smart clients store a map
Shard S1 = slots 0 – 3276
Shard S2 = slots 3277 – 6553
Shard S3 = slots 6554 – 9829
Shard S4 = slots 9830 – 13106
Shard S5 = slots 13107 - 16383
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Availability Zone A
slots 0 - 5454 slots 5455 – 10909
Redis Cluster
Redis Cluster – Architecture
slots 10910 – 16363
Availability Zone B Availability Zone C
slots 5455 – 10909
slots 5455 – 10909slots 0 - 5454 slots 0 - 5454
slots 10910 – 16363
slots 10910 – 16363
Redis Cluster – Multi AZ
A cluster consists of 1 to 15 shards
example: 3 shard cluster,
2 read replicas
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Availability Zone A
slots 0 - 5454
Redis Cluster
Redis Cluster – Architecture
slots 10910 – 16363
Availability Zone B Availability Zone C
slots 5455 – 10909
slots 5455 – 10909slots 0 - 5454 slots 0 - 5454
slots 10910 – 16363
Shard
ReplicaReplicaPrimary
Each shard has a Primary Node
and up to 5 replica nodes
slots 5455 – 10909
slots 10910 – 16363
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Availability Zone A
slots 0 - 5454 slots 5455 – 10909
Redis Cluster
Redis Cluster – Architecture
slots 10910 – 16363
Availability Zone B Availability Zone C
slots 5455 – 10909
slots 5455 – 10909
Shard
ReplicaReplica Primary
Each shard has a Primary Node
and up to 5 replica nodes
slots 0 - 5454 slots 0 - 5454
slots 10910 – 16363
slots 10910 – 16363
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Availability Zone A
slots 0 - 5454
Redis Cluster
Redis Cluster – Architecture
slots 10910 – 16363
Availability Zone B Availability Zone C
slots 10910 – 16363
slots 10910 – 16363
Shard
Replica PrimaryReplica
Each shard has a Primary Node
and up to 5 replica nodes
slots 5455 – 10909 slots 0 - 5454
slots 5455 – 10909
slots 0 - 5454 slots 5455 – 10909
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Setting up Redis Cluster - Console
Cluster Name
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Setting up Redis Cluster - Console
Redis Version
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Setting up Redis Cluster - Console
Instance
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Setting up Redis Cluster - Console
# of Shards
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Setting up Redis Cluster - Console
# of Replica’s
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Slots Distribution
Setting up Redis Cluster - Console
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Select AZs
Setting up Redis Cluster - Console
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
ElastiCache for Redis Failure Scenarios
“Everything fails, all the time.”
GET quote:failureREDIS:6379>
-- Werner Vogels, CTO Amazon.com --
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Availability Zone A
slots 0 - 5454 slots 5455 – 10909
Redis Cluster
slots 10910 – 16363
Availability Zone B Availability Zone C
slots 5455 – 10909 slots 5455 – 10909slots 0 - 5454 slots 0 - 5454
slots 10910 – 16363 slots 10910 – 16363
Scenario 1: Single Primary Failure
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Availability Zone A
slots 0 - 5454 slots 5455 – 10909
Redis Cluster
Scenario 1: Single Primary Failure
slots 10910 – 16363
Availability Zone B Availability Zone C
slots 5455 – 10909 slots 5455 – 10909slots 0 - 5454 slots 0 - 5454
slots 10910 – 16363
Mitigation:
1. Automatic Failure Detection & Replica Promotion (~15-30s)
2. Repair Failed Node
slots 10910 – 16363
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Availability Zone A
slots 0 - 5454 slots 5455 – 10909
Redis Cluster
Scenario 2: Majority of Primaries Fail
slots 10910 – 16363
Availability Zone B Availability Zone C
slots 5455 – 10909 slots 5455 – 10909slots 0 - 5454 slots 0 - 5454
slots 10910 – 16363slots 10910 – 16363
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Availability Zone A
slots 0 - 5454 slots 5455 – 10909
Redis Cluster
slots 10910 – 16363
Availability Zone B Availability Zone C
slots 5455 – 10909 slots 5455 – 10909slots 0 - 5454 slots 0 - 5454
Mitigation: Redis enhancements on ElastiCache
• Automatic Failure Detection and Replica Promotion
• Repair Failed Nodes
slots 10910 – 16363slots 10910 – 16363
Scenario 2: Majority of Primaries Fail
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Feature Enabled Disabled
FAILOVER 15-30s
(NON-DNS)
1.5m-2m
(DNS BASED)
FAILOVER RISK • WRITES effected - Partial dataset (less risk
with more partitions)
• READS available
• Writes effected on entire dataset.
• READS available
PERFORMANCE SCALES with cluster size
(90 nodes – 15 primaries + 0-5 replicas per shard.
6 Nodes (1 Primary + 0-5 replicas)
MAX CONNECTIONS • PRIMARIES (65K X 15 = 975,000)
• REPLICAS (65K X 75 = 4,875,000)
• PRIMARY: 65K
• REPLICAS: (65K x 5 = 325,000)
STORAGE 3.5TiB + 237GB
COST
Example:
Assume workload needs 175GB
Smaller nodes but more $$
9 x cache.r3.xlarge (0.455hr) = $4.095hr 255.6 GB
Larger nodes less $
1 X cache.r3.8xlarge = $3.640 , 237 GB
REDIS CLUSTER-MODE ENABLED VS DISABLED
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
ElastiCache Best Practices
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Cluster Sizing Best Practices
• Storage – Clusters should have adequate Memory
• Recommended: Memory needed + 25% reserved memory (for Redis) + some room for growth
(optional 10%).
• Optimize using eviction policies and TTLs
• Scale up or out when before reaching max-memory using Cloudwatch alarms
• Use memory optimized nodes for cost effectiveness
• Performance – Performance should not be compromised
• Benchmark operations using Redis Benchmark tool
• For more READIOPS – Add Replicas
• For more WRITEIOPS – Add shards (scale out)
• For more Network IO – Use network optimized instances and scale out
• Use pipelining for bulk reads/writes
• Consider Big(O) time complexity for data structure commands
• Cluster Isolation (apps sharing key space) – Chose a strategy that works for your workload
• Identify what kind of isolation is needed based on the workload and environment
• Isolation: No Isolation $ | Isolation by Purpose $$ | Full Isolation $$$
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Redis Benchmark Tool
Open source utility to benchmark performance
• example: src/redis-benchmark -h r3-xlarge-perf.foio87.0001.use1.cache.amazonaws.com -p 6379 -n -150000 -d 100
Syntax:
redis-benchmark -h <host> -p <port> -c 50 -n 1000 -d 500 –q
-c <clients> - Specifies the number of parallel connections (default 50).
-n <requests> - Specifies the number of requests (default 1000000).
-d <size> - Specifies the data size of GET and SET values in bytes.
-t <test1,test2> - Comma separated list of tests to perform.
-q – Quiet operation, displays only the result.
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Redis max-memory Policies
Select a max-memory policy based on your workload needs
• noeviction: return errors when the memory limit was reached and the client is trying
to execute commands that could result in more memory to be used.
• allkeys-lru: evict keys trying to remove the less recently used (LRU) keys first.
• volatile-lru: evict keys trying to remove the less recently used (LRU) keys first, but only
among keys that have an expire set.
• allkeys-random: evict random keys in order to make space for the new data added.
• volatile-random: evict random keys in order to make space for the new data added, but
only evict keys with an expire set.
• volatile-ttl: evict only keys with an expire set, and try to evict keys with a shorter time
to live (TTL) first.
The policies volatile-lru, volatile-random and volatile-ttl behave like noeviction if there are
no keys to evict matching the prerequisites.
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Architecting for Availability & Performance
• Upgrade to the latest engine version – 3.2.4
• Set reserved-memory to 25-30% of total available memory
• Swap usage should be zero or very low. Scale if not.
• Put read-replicas in a different AZ from the primary
• For important workloads use 2 read replicas per primary
• Write to the primary, read from the read-replicas
• Take snapshots from read-replicas
• For Redis Cluster have odd number of shards.
• Use newer Intel processors for best IO performance
• Use Failover API to environment
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Key ElastiCache CloudWatch Metrics
• CPUUtilization
• Memcached – up to 90% ok
• Redis – divide by cores (ex: 90% / 4 = 22.5%)
• SwapUsage low
• CacheMisses / CacheHits Ratio low / stable
• Evictions near zero
• Exception: Russian doll caching
• CurrConnections stable
• Setup alarms with CloudWatch Metrics
• Whitepaper: http://bit.ly/elasticache-whitepaper
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
ElastiCache Modifiable Parameters
– Maxclients: 65000 (unchangeable)
• Use connection pooling
• timeout – Closes a connection after its been idle for a given interval
• tcp-keepalive – Detects dead peers given an interval
– Databases: 16 (Default)
• Logical partition
– Reserved-memory: 0 (Default)
• Recommended
 50% of maxmemory to use before 2.8.22
 25% after 2.8.22 – ElastiCache
– Maxmemory-policy:
• The eviction policy for keys when maximum memory usage is reached.
• Possible values: volatile-lru, allkeys-lru, volatile-random, allkeys-random,
volatile-ttl, noeviction
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Common Usage Patterns
Amazon ElastiCache
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Usage Patterns
Session
Management
Database
Caching
APIs
(HTTP responses)
IOT
Streaming Data
Analytics
(Filtering/Aggregation)
Pub/Sub
Social Media
(Sentiment Analysis)
Standalone
Database
(Metadata Store)
Leaderboards
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Caching
Clients
Amazon
ElastiCache
Redis
Amazon
DynamoDB
Elastic Load
Balancing
Amazon
EC2
Amazon
RDS
write-through
reads/
writes
DDB streams
mysql.lambda_async
reads/
writes
https://aws.amazon.com/caching/database-caching/
Amazon
S3
reads/ writes
Object data
Unstructured data
Relational data
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Amazon
EC2
reads/
writes
Amazon
ElastiCache
Redis
reads
MongoDB
Cluster
DBObject doc = collection.findOne();
Cache Serialized DBObject in Redis (Good)
Cache rows in Redis Hash (Faster/More efficient)
Cassandra
Cluster
Amazon
ElastiCache
Redis
Amazon
EC2
reads/
writes
reads
ResultSet rs = session.execute(stmt);
Cache Serialized ResultSet in Redis (Good)
Cache rows in Redis Hash (Faster/More efficient)
Caching NoSQL Databases with ElastiCache
 Smaller NoSQL DB Clusters needed = Lower Costs
 Faster Data Retrieval = Better Performance
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
• 1) Install php, apache php memcache client
• e.g. yum install php apache php-pecl-memcache
• 2) Configure “php.ini”
• session.save_handler = memcache
• session.save_path=
• "tcp://node1:11211, tcp://node2:11211"
• 3) Configure “php.d/memcache.ini”
• memcache.hash_strategy = consistent
• memcache.allow_failover = 1
• memcache.session_redundancy=3*
• 4) Restart httpd
• 5) Begin using Session Data:
Auto Scaling group
• For situations where you need an
external session store
• Especially needed when using ASGs
• Cache is optimal for high-volume
reads
PHP Example
Session Caching
https://github.com/mikelabib/elasticache-memcached-php-demo
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Amazon
Kinesis
Analytics
Amazon
Kinesis
Streams
Amazon
Kinesis
Streams
Amazon
ElastiCache
(Redis)
cleansed
stream
Streaming Data Enrichment / Processing
DataSources
raw
stream
Subscribers
Lambda Function 1
ContinualData
Filtering/Enrichment
Real-time
Pub/Sub
Lambda Function 2
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Big Data Architectures using Redis
Amazon Kinesis
DataSources
AWS Lambda
Apache Storm
on EMR
Spark Streaming
on EMR
Amazon Kinesis
App
Amazon
EC2
AWS IoT
Amazon
ElastiCache
Collect
Store
Process
Amazon
S3
Apache Kafka
AWS
Lambda
Custom
App
Spark on
EMR
Analyze
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Rules Engine
Amazon
ElastiCache
Redis
AWS
Lambda
Direct Integration
LambdaSNS SQS
S3 KinesisDDB
AWS
IoT Devices
AWS
IoT
Sensor Store
IoT powered by ElastiCache
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
IoT Demo – AWS IoT + Lambda + ElastiCache
https://aws.amazon.com/blogs/database/managing-iot-and-time-series-data-with-amazon-elasticache-for-redis/
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Mobile Apps Powered by ElastiCache
Amazon API
Gateway
AWS
Lambda
Amazon
ElastiCache
Redis
GEOADD
GEORADIUS
Search points of interest
Update points of interest
https://aws.amazon.com/blogs/database/amazon-elasticache-utilizing-redis-geospatial-capabilities/
Amazon
DynamoDB
DDB streams
Amazon
EC2
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Ad Tech
Clients
Advertisers
https://aws.amazon.com/caching/database-caching/
Ad Network
Ad Slot
Consumer
Ad Slot
Publishers
Ad Placement
(Websites/Apps)
Amazon
ElastiCache
Redis
<40 ms
Clickstream
(Shopping
Events)
User visits
page
Publisher
places ad
slot for
auction
Ad Network
calls for bids
Bidders
respond with
bids
Winners bid
Ad displayed
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Chat Apps powered by ElastiCache
https://aws.amazon.com/blogs/database/amazon-elasticache-utilizing-redis-geospatial-capabilities/
Clients
Chat Apps
Application Load
Balancer
WebSockets
Amazon
ElastiCache
Redis
PubSub
Serverpersistent
connections
Elastic
Beanstalk
SUBSCRIBE chat_channel:114
PUBLISH chat_channel:114 "Hello all"
>> ["message", "chat_channel:114", "Hello all"]
UNSUBSCRIBE chat_channel:114
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
• Very popular for gaming apps which 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
Gaming - Real-time Leaderboard
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
• 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
Rate Limiting
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
• 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
Recommendation Engine - Ratings
INCR item:38927:likes
HSET item:38927:ratings "Susan" 1
INCR item:38927:dislikes
HSET item:38927:ratings "Tommy" -1
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Database Caching Strategies
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Web
App
RDS DB
instancestandby
(multi-AZ)
MS SQL
instance
 Scalability
 Durability
Latency
 Cost
Auto Scaling
Auto Scaling
WHY CACHING
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Web
App
RDS DB
instancestandby
(multi-AZ)
MS SQL
instance
Auto Scaling
Auto Scaling
Scalability
 Durability
Latency
 Cost
WHY CACHING
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Web
App
RDS DB
instancestandby
(multi-AZ)
MS SQL
instance
 Scalability
 Durability
Latency
Cost
Auto Scaling
Auto Scaling
WHY CACHING
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
App
RDS DB
instancestandby
(multi-AZ)
MS SQL
instance
 Scalability
 Durability
 Latency
 Cost
Auto Scaling
Auto Scaling
Web
WHY CACHING
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Caching - Patterns
Cache-Aside - Lazy Loading
Amazon
ElastiCache
Applications
Amazon
RDS
1
2
3
1.) Check Cache, if HIT return
2.) If Cache MISS
3.) Update Cache
https://d0.awsstatic.com/whitepapers/Database/database-caching-strategies-using-redis.pdf
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Caching - Patterns
Cache-Aside - Write-Through
Amazon
ElastiCache
Applications
Amazon
RDS
1
2
1.) Update Primary DB
2.) Update Cache
https://d0.awsstatic.com/whitepapers/Database/database-caching-strategies-using-redis.pdf
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Java App Java App
Web Server Web Server
Database Cache
Customers
AZ1 AZ2
Distributed
Cache
Example workload topology: Customer Data
CustomerDB Primary CustomerDB Standby
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Caching Strategies
1. Cache Database SQL ResultSet (Row)
PRO
When data retrieval logic is abstracted from the code consuming the ResultSet, caching the ROW can
be extremely effective and can be implemented against any RDBMS.
CON
• Does not speed up processing time
SELECT * FROM x WHERE y
ID First_Name Last_Name City
123 Michael Labib Chicago
ResultSet Object (ROW) Key: Query, Value: CRS as byte array
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Caching Strategies
2. Cache database values into custom format in a Redis String
SELECT * FROM x WHERE y
ID First_Name Last_Name City
123 Michael Labib Chicago
String firstName = rs.getString(First_Name)
PRO
Very easy to implement. Cache any desired database fields and values into a Redis String. For example,
store your retrieved data into a JSON object stored in a Redis String.
CON
No JSON specific query support
Key: 123, Value: ‘{ “firstname”: “Michael”,
“lastname”: “Labib”,
“city”: “Chicago” } ‘
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Caching Strategies
3. Cache serialized application object (e.g. Java Object )
SELECT * FROM x WHERE y
ID First_Name Last_Name City
123 Michael Labib Chicago
Key: CUSTOMER_ID:123,
Value: Customer Object as byte array
String firstName = rs.getString(First_Name);
customer.setFirstName(firstName);
String lastName = rs.getString(Last_Name);
customer.setLastName(lastName);
PRO
Utilize application objects in their native structure and data state when serialized.
CON
Advanced application development use case.
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Caching Strategies
4. Leverage advanced Redis Data Structures for cached data
SELECT * FROM x WHERE y
ID First_Name Last_Name City
123 Michael Labib Chicago
Key: CUSTOMER_ID:123, Value: rsHash
String firstName = rs.getString(First_Name);
rsHash.put(“firstName", firstName);
String lastName = rs.getString(Last_Name);
rsHash.put(“lastName", lastName);
jedis.hmset(“CUSTOMER_ID:123", rsHash);
PRO
In addition to reducing data retrieval latency, cache data into specific data structure that simplifies the
data access pattern.
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
aws.amazon.com/activate
Everything and Anything Startups
Need to Get Started on AWS

More Related Content

What's hot

Unleash the Power of Redis with Amazon ElastiCache
Unleash the Power of Redis with Amazon ElastiCacheUnleash the Power of Redis with Amazon ElastiCache
Unleash the Power of Redis with Amazon ElastiCacheAmazon Web Services
 
ElastiCache Deep Dive: Best Practices and Usage Patterns - March 2017 AWS Onl...
ElastiCache Deep Dive: Best Practices and Usage Patterns - March 2017 AWS Onl...ElastiCache Deep Dive: Best Practices and Usage Patterns - March 2017 AWS Onl...
ElastiCache Deep Dive: Best Practices and Usage Patterns - March 2017 AWS Onl...Amazon Web Services
 
Deep Dive on PostgreSQL Databases on Amazon RDS (DAT324) - AWS re:Invent 2018
Deep Dive on PostgreSQL Databases on Amazon RDS (DAT324) - AWS re:Invent 2018Deep Dive on PostgreSQL Databases on Amazon RDS (DAT324) - AWS re:Invent 2018
Deep Dive on PostgreSQL Databases on Amazon RDS (DAT324) - AWS re:Invent 2018Amazon Web Services
 
Getting Strated with Amazon Dynamo DB (Jim Scharf) - AWS DB Day
Getting Strated with Amazon Dynamo DB (Jim Scharf) - AWS DB DayGetting Strated with Amazon Dynamo DB (Jim Scharf) - AWS DB Day
Getting Strated with Amazon Dynamo DB (Jim Scharf) - AWS DB DayAmazon Web Services Korea
 
Caching solutions with Redis
Caching solutions   with RedisCaching solutions   with Redis
Caching solutions with RedisGeorge Platon
 
Amazon Dynamo DB 활용하기 - 강민석 :: AWS Database Modernization Day 온라인
Amazon Dynamo DB 활용하기 - 강민석 :: AWS Database Modernization Day 온라인Amazon Dynamo DB 활용하기 - 강민석 :: AWS Database Modernization Day 온라인
Amazon Dynamo DB 활용하기 - 강민석 :: AWS Database Modernization Day 온라인Amazon Web Services Korea
 
[AWS Dev Day] 앱 현대화 | AWS Fargate를 사용한 서버리스 컨테이너 활용 하기 - 삼성전자 개발자 포털 사례 - 정영준...
[AWS Dev Day] 앱 현대화 | AWS Fargate를 사용한 서버리스 컨테이너 활용 하기 - 삼성전자 개발자 포털 사례 - 정영준...[AWS Dev Day] 앱 현대화 | AWS Fargate를 사용한 서버리스 컨테이너 활용 하기 - 삼성전자 개발자 포털 사례 - 정영준...
[AWS Dev Day] 앱 현대화 | AWS Fargate를 사용한 서버리스 컨테이너 활용 하기 - 삼성전자 개발자 포털 사례 - 정영준...Amazon Web Services Korea
 
Dd and atomic ddl pl17 dublin
Dd and atomic ddl pl17 dublinDd and atomic ddl pl17 dublin
Dd and atomic ddl pl17 dublinStåle Deraas
 
Deep Dive Into Elasticsearch
Deep Dive Into ElasticsearchDeep Dive Into Elasticsearch
Deep Dive Into ElasticsearchKnoldus Inc.
 
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the CloudAmazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the CloudNoritaka Sekiyama
 
Protecting Your Data with Encryption on AWS
Protecting Your Data with Encryption on AWSProtecting Your Data with Encryption on AWS
Protecting Your Data with Encryption on AWSAmazon Web Services
 
Aurora MySQL Backtrack을 이용한 빠른 복구 방법 - 진교선 :: AWS Database Modernization Day 온라인
Aurora MySQL Backtrack을 이용한 빠른 복구 방법 - 진교선 :: AWS Database Modernization Day 온라인Aurora MySQL Backtrack을 이용한 빠른 복구 방법 - 진교선 :: AWS Database Modernization Day 온라인
Aurora MySQL Backtrack을 이용한 빠른 복구 방법 - 진교선 :: AWS Database Modernization Day 온라인Amazon Web Services Korea
 
MySQL Advanced Administrator 2021 - 네오클로바
MySQL Advanced Administrator 2021 - 네오클로바MySQL Advanced Administrator 2021 - 네오클로바
MySQL Advanced Administrator 2021 - 네오클로바NeoClova
 

What's hot (20)

Unleash the Power of Redis with Amazon ElastiCache
Unleash the Power of Redis with Amazon ElastiCacheUnleash the Power of Redis with Amazon ElastiCache
Unleash the Power of Redis with Amazon ElastiCache
 
ElastiCache Deep Dive: Best Practices and Usage Patterns - March 2017 AWS Onl...
ElastiCache Deep Dive: Best Practices and Usage Patterns - March 2017 AWS Onl...ElastiCache Deep Dive: Best Practices and Usage Patterns - March 2017 AWS Onl...
ElastiCache Deep Dive: Best Practices and Usage Patterns - March 2017 AWS Onl...
 
AWS RDS
AWS RDSAWS RDS
AWS RDS
 
Deep Dive on PostgreSQL Databases on Amazon RDS (DAT324) - AWS re:Invent 2018
Deep Dive on PostgreSQL Databases on Amazon RDS (DAT324) - AWS re:Invent 2018Deep Dive on PostgreSQL Databases on Amazon RDS (DAT324) - AWS re:Invent 2018
Deep Dive on PostgreSQL Databases on Amazon RDS (DAT324) - AWS re:Invent 2018
 
Getting Strated with Amazon Dynamo DB (Jim Scharf) - AWS DB Day
Getting Strated with Amazon Dynamo DB (Jim Scharf) - AWS DB DayGetting Strated with Amazon Dynamo DB (Jim Scharf) - AWS DB Day
Getting Strated with Amazon Dynamo DB (Jim Scharf) - AWS DB Day
 
Caching solutions with Redis
Caching solutions   with RedisCaching solutions   with Redis
Caching solutions with Redis
 
Deep Dive on Amazon DynamoDB
Deep Dive on Amazon DynamoDBDeep Dive on Amazon DynamoDB
Deep Dive on Amazon DynamoDB
 
AWS DynamoDB and Schema Design
AWS DynamoDB and Schema DesignAWS DynamoDB and Schema Design
AWS DynamoDB and Schema Design
 
Amazon Dynamo DB 활용하기 - 강민석 :: AWS Database Modernization Day 온라인
Amazon Dynamo DB 활용하기 - 강민석 :: AWS Database Modernization Day 온라인Amazon Dynamo DB 활용하기 - 강민석 :: AWS Database Modernization Day 온라인
Amazon Dynamo DB 활용하기 - 강민석 :: AWS Database Modernization Day 온라인
 
Deep Dive: Amazon RDS
Deep Dive: Amazon RDSDeep Dive: Amazon RDS
Deep Dive: Amazon RDS
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
[AWS Dev Day] 앱 현대화 | AWS Fargate를 사용한 서버리스 컨테이너 활용 하기 - 삼성전자 개발자 포털 사례 - 정영준...
[AWS Dev Day] 앱 현대화 | AWS Fargate를 사용한 서버리스 컨테이너 활용 하기 - 삼성전자 개발자 포털 사례 - 정영준...[AWS Dev Day] 앱 현대화 | AWS Fargate를 사용한 서버리스 컨테이너 활용 하기 - 삼성전자 개발자 포털 사례 - 정영준...
[AWS Dev Day] 앱 현대화 | AWS Fargate를 사용한 서버리스 컨테이너 활용 하기 - 삼성전자 개발자 포털 사례 - 정영준...
 
Introducing DynamoDB
Introducing DynamoDBIntroducing DynamoDB
Introducing DynamoDB
 
Dd and atomic ddl pl17 dublin
Dd and atomic ddl pl17 dublinDd and atomic ddl pl17 dublin
Dd and atomic ddl pl17 dublin
 
Deep Dive Into Elasticsearch
Deep Dive Into ElasticsearchDeep Dive Into Elasticsearch
Deep Dive Into Elasticsearch
 
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the CloudAmazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
 
Protecting Your Data with Encryption on AWS
Protecting Your Data with Encryption on AWSProtecting Your Data with Encryption on AWS
Protecting Your Data with Encryption on AWS
 
Aurora MySQL Backtrack을 이용한 빠른 복구 방법 - 진교선 :: AWS Database Modernization Day 온라인
Aurora MySQL Backtrack을 이용한 빠른 복구 방법 - 진교선 :: AWS Database Modernization Day 온라인Aurora MySQL Backtrack을 이용한 빠른 복구 방법 - 진교선 :: AWS Database Modernization Day 온라인
Aurora MySQL Backtrack을 이용한 빠른 복구 방법 - 진교선 :: AWS Database Modernization Day 온라인
 
MySQL Advanced Administrator 2021 - 네오클로바
MySQL Advanced Administrator 2021 - 네오클로바MySQL Advanced Administrator 2021 - 네오클로바
MySQL Advanced Administrator 2021 - 네오클로바
 
Introduction to AWS Glue
Introduction to AWS Glue Introduction to AWS Glue
Introduction to AWS Glue
 

Similar to Unleash the Power of Redis with Amazon ElastiCache

Scaling Redis Workloads with Amazon ElastiCache - AWS Online Tech Talks
Scaling Redis Workloads with Amazon ElastiCache - AWS Online Tech TalksScaling Redis Workloads with Amazon ElastiCache - AWS Online Tech Talks
Scaling Redis Workloads with Amazon ElastiCache - AWS Online Tech TalksAmazon Web Services
 
DAT341_Working with Amazon ElastiCache for Redis
DAT341_Working with Amazon ElastiCache for RedisDAT341_Working with Amazon ElastiCache for Redis
DAT341_Working with Amazon ElastiCache for RedisAmazon Web Services
 
DAT305_Amazon ElastiCache Deep Dive
DAT305_Amazon ElastiCache Deep DiveDAT305_Amazon ElastiCache Deep Dive
DAT305_Amazon ElastiCache Deep DiveAmazon Web Services
 
RedisConf17 - Turbo-charge your apps with Amazon Elasticache for Redis
RedisConf17 - Turbo-charge your apps with Amazon Elasticache for RedisRedisConf17 - Turbo-charge your apps with Amazon Elasticache for Redis
RedisConf17 - Turbo-charge your apps with Amazon Elasticache for RedisRedis Labs
 
Amazon Elasticache and Redis
Amazon Elasticache and RedisAmazon Elasticache and Redis
Amazon Elasticache and RedisMikhail Prudnikov
 
Amazon Elasticache Deep Dive - March 2017 AWS Online Tech Talks
Amazon Elasticache Deep Dive - March 2017 AWS Online Tech TalksAmazon Elasticache Deep Dive - March 2017 AWS Online Tech Talks
Amazon Elasticache Deep Dive - March 2017 AWS Online Tech TalksAmazon Web Services
 
ElastiCache: Deep Dive Best Practices and Usage Patterns - AWS Online Tech Talks
ElastiCache: Deep Dive Best Practices and Usage Patterns - AWS Online Tech TalksElastiCache: Deep Dive Best Practices and Usage Patterns - AWS Online Tech Talks
ElastiCache: Deep Dive Best Practices and Usage Patterns - AWS Online Tech TalksAmazon Web Services
 
Hands-On with Amazon ElastiCache for Redis - Workshop (DAT309-R1) - AWS re:In...
Hands-On with Amazon ElastiCache for Redis - Workshop (DAT309-R1) - AWS re:In...Hands-On with Amazon ElastiCache for Redis - Workshop (DAT309-R1) - AWS re:In...
Hands-On with Amazon ElastiCache for Redis - Workshop (DAT309-R1) - AWS re:In...Amazon Web Services
 
Fast Data at Scale - AWS Summit Tel Aviv 2017
Fast Data at Scale - AWS Summit Tel Aviv 2017Fast Data at Scale - AWS Summit Tel Aviv 2017
Fast Data at Scale - AWS Summit Tel Aviv 2017Amazon Web Services
 
ElastiCache Deep Dive: Design Patterns for In-Memory Data Stores (DAT302-R1) ...
ElastiCache Deep Dive: Design Patterns for In-Memory Data Stores (DAT302-R1) ...ElastiCache Deep Dive: Design Patterns for In-Memory Data Stores (DAT302-R1) ...
ElastiCache Deep Dive: Design Patterns for In-Memory Data Stores (DAT302-R1) ...Amazon Web Services
 
China Gaming Industry Experience and Architecture Sharing
China Gaming Industry Experience and Architecture SharingChina Gaming Industry Experience and Architecture Sharing
China Gaming Industry Experience and Architecture SharingAmazon Web Services
 
中國AWS遊戲業經驗和架構分享
中國AWS遊戲業經驗和架構分享中國AWS遊戲業經驗和架構分享
中國AWS遊戲業經驗和架構分享Amazon Web Services
 
Using Databases and Containers From Development to Deployment
Using Databases and Containers  From Development to DeploymentUsing Databases and Containers  From Development to Deployment
Using Databases and Containers From Development to DeploymentAerospike, Inc.
 
GAM307_Ubisoft How For Honor Runs Using Amazon ECS
GAM307_Ubisoft How For Honor Runs Using Amazon ECSGAM307_Ubisoft How For Honor Runs Using Amazon ECS
GAM307_Ubisoft How For Honor Runs Using Amazon ECSAmazon Web Services
 
Building Multiregion Serverless Backends
Building Multiregion Serverless BackendsBuilding Multiregion Serverless Backends
Building Multiregion Serverless BackendsAmazon Web Services
 
Architecting SAP on Amazon Web Services - SVC216 - Chicago AWS Summit
Architecting SAP on Amazon Web Services - SVC216 - Chicago AWS SummitArchitecting SAP on Amazon Web Services - SVC216 - Chicago AWS Summit
Architecting SAP on Amazon Web Services - SVC216 - Chicago AWS SummitAmazon Web Services
 

Similar to Unleash the Power of Redis with Amazon ElastiCache (20)

Scaling Redis Workloads with Amazon ElastiCache - AWS Online Tech Talks
Scaling Redis Workloads with Amazon ElastiCache - AWS Online Tech TalksScaling Redis Workloads with Amazon ElastiCache - AWS Online Tech Talks
Scaling Redis Workloads with Amazon ElastiCache - AWS Online Tech Talks
 
DAT341_Working with Amazon ElastiCache for Redis
DAT341_Working with Amazon ElastiCache for RedisDAT341_Working with Amazon ElastiCache for Redis
DAT341_Working with Amazon ElastiCache for Redis
 
DAT305_Amazon ElastiCache Deep Dive
DAT305_Amazon ElastiCache Deep DiveDAT305_Amazon ElastiCache Deep Dive
DAT305_Amazon ElastiCache Deep Dive
 
Amazon ElastiCache and Redis
Amazon ElastiCache and RedisAmazon ElastiCache and Redis
Amazon ElastiCache and Redis
 
ElastiCache and Redis
ElastiCache and RedisElastiCache and Redis
ElastiCache and Redis
 
Amazon ElastiCache and Redis
Amazon ElastiCache and RedisAmazon ElastiCache and Redis
Amazon ElastiCache and Redis
 
RedisConf17 - Turbo-charge your apps with Amazon Elasticache for Redis
RedisConf17 - Turbo-charge your apps with Amazon Elasticache for RedisRedisConf17 - Turbo-charge your apps with Amazon Elasticache for Redis
RedisConf17 - Turbo-charge your apps with Amazon Elasticache for Redis
 
Amazon Elasticache and Redis
Amazon Elasticache and RedisAmazon Elasticache and Redis
Amazon Elasticache and Redis
 
Amazon Elasticache Deep Dive - March 2017 AWS Online Tech Talks
Amazon Elasticache Deep Dive - March 2017 AWS Online Tech TalksAmazon Elasticache Deep Dive - March 2017 AWS Online Tech Talks
Amazon Elasticache Deep Dive - March 2017 AWS Online Tech Talks
 
ElastiCache: Deep Dive Best Practices and Usage Patterns - AWS Online Tech Talks
ElastiCache: Deep Dive Best Practices and Usage Patterns - AWS Online Tech TalksElastiCache: Deep Dive Best Practices and Usage Patterns - AWS Online Tech Talks
ElastiCache: Deep Dive Best Practices and Usage Patterns - AWS Online Tech Talks
 
Hands-On with Amazon ElastiCache for Redis - Workshop (DAT309-R1) - AWS re:In...
Hands-On with Amazon ElastiCache for Redis - Workshop (DAT309-R1) - AWS re:In...Hands-On with Amazon ElastiCache for Redis - Workshop (DAT309-R1) - AWS re:In...
Hands-On with Amazon ElastiCache for Redis - Workshop (DAT309-R1) - AWS re:In...
 
Fast Data at Scale - AWS Summit Tel Aviv 2017
Fast Data at Scale - AWS Summit Tel Aviv 2017Fast Data at Scale - AWS Summit Tel Aviv 2017
Fast Data at Scale - AWS Summit Tel Aviv 2017
 
ElastiCache Deep Dive: Design Patterns for In-Memory Data Stores (DAT302-R1) ...
ElastiCache Deep Dive: Design Patterns for In-Memory Data Stores (DAT302-R1) ...ElastiCache Deep Dive: Design Patterns for In-Memory Data Stores (DAT302-R1) ...
ElastiCache Deep Dive: Design Patterns for In-Memory Data Stores (DAT302-R1) ...
 
China Gaming Industry Experience and Architecture Sharing
China Gaming Industry Experience and Architecture SharingChina Gaming Industry Experience and Architecture Sharing
China Gaming Industry Experience and Architecture Sharing
 
中國AWS遊戲業經驗和架構分享
中國AWS遊戲業經驗和架構分享中國AWS遊戲業經驗和架構分享
中國AWS遊戲業經驗和架構分享
 
Using Databases and Containers From Development to Deployment
Using Databases and Containers  From Development to DeploymentUsing Databases and Containers  From Development to Deployment
Using Databases and Containers From Development to Deployment
 
SD Times - Docker v2
SD Times - Docker v2SD Times - Docker v2
SD Times - Docker v2
 
GAM307_Ubisoft How For Honor Runs Using Amazon ECS
GAM307_Ubisoft How For Honor Runs Using Amazon ECSGAM307_Ubisoft How For Honor Runs Using Amazon ECS
GAM307_Ubisoft How For Honor Runs Using Amazon ECS
 
Building Multiregion Serverless Backends
Building Multiregion Serverless BackendsBuilding Multiregion Serverless Backends
Building Multiregion Serverless Backends
 
Architecting SAP on Amazon Web Services - SVC216 - Chicago AWS Summit
Architecting SAP on Amazon Web Services - SVC216 - Chicago AWS SummitArchitecting SAP on Amazon Web Services - SVC216 - Chicago AWS Summit
Architecting SAP on Amazon Web Services - SVC216 - Chicago AWS Summit
 

More from Amazon Web Services

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...Amazon Web Services
 
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...Amazon Web Services
 
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 FargateAmazon Web Services
 
Costruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWSCostruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWSAmazon Web Services
 
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 Amazon Web Services
 
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...Amazon Web Services
 
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...Amazon Web Services
 
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 WorkloadsAmazon Web Services
 
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 sfatareAmazon Web Services
 
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 NodeJSAmazon Web Services
 
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 webAmazon Web Services
 
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 sfatareAmazon 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 AWSAmazon 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 DeckAmazon Web Services
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without serversAmazon 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
 
Introduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceIntroduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceAmazon 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
 

Unleash the Power of Redis with Amazon ElastiCache

  • 1. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Unleash the power of Redis with Amazon ElastiCache Michael Labib, Specialist Solutions Architect
  • 2. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved What we’ll cover • ElastiCache Redis Overview • Common Architecture Patterns • Best Practices • Caching Strategies
  • 3. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved In-Memory Key-Value Store High-performance Redis and Memcached Fully managed; Zero admin Highly Available and Reliable Hardened by Amazon Amazon ElastiCache
  • 4. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Request Rate High Low Latency Low High Structure Low High Data Volume Low High Amazon RDS Amazon S3 Amazon Glacier Amazon CloudSearch and Amazon Elasticsearch Amazon DynamoDB Amazon ElastiCache and DAX HDFS
  • 5. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Redis – The In-Memory Leader Powerful ~200 commands + Lua scripting In-memory data structure server Utility data structures strings, lists, hashes, sets, sorted sets, bitmaps & HyperLogLogs Simple Atomic operations supports transactions Ridiculously fast! <1ms latency for most commands Highly Available replication Persistence Open Source
  • 6. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Redis Data Types & More! Run Lua scripts Geospatial Queries! Pub / Sub
  • 7. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Amazon ElastiCache Optimized Swap Memory •Mitigate the risk of increased swap usage during syncs and snapshots. Dynamic write throttling •Improved output buffer management when the node’s memory is close to being exhausted. Smoother failovers •Clusters recover faster as replicas avoid flushing their data to do a full re-sync with the primary. ElastiCache Engine Enhancements Enhanced failover quorum logic When majority primary nodes are missing, the cluster is still operational
  • 8. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved ElastiCache Redis Topologies
  • 9. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved ElastiCache Redis with Multi-AZ (non-clustered)
  • 10. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved 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
  • 11. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved ElastiCache with Redis Multi-AZ Region Availability Zone A Availability Zone B ElastiCache Cluster Auto Scaling Primary Read Replica
  • 12. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved ElastiCache with Redis Multi-AZ Region Availability Zone A Availability Zone B Primary Read Replica Auto Scaling ElastiCache Cluster
  • 13. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved ElastiCache with Redis Multi-AZ Region Availability Zone A Availability Zone B Primary Read Replica Auto Scaling ElastiCache Cluster
  • 14. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Scaling with Redis Cluster (clustered mode enabled)
  • 15. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Scaling with Redis Cluster (clustered mode enabled)
  • 16. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Setting up Redis Cluster - Console Cluster Mode
  • 17. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Redis Cluster – Automatic Client-Side Sharding S5 S1 S2 S4 S3 Client • 16384 hash slots per Cluster • Slot for a key is CRC16 modulo {key} • Slots are distributed across the Cluster into Shards • Developers must use a Redis cluster client! • Clients are redirected to the correct shard • Smart clients store a map Shard S1 = slots 0 – 3276 Shard S2 = slots 3277 – 6553 Shard S3 = slots 6554 – 9829 Shard S4 = slots 9830 – 13106 Shard S5 = slots 13107 - 16383
  • 18. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Availability Zone A slots 0 - 5454 slots 5455 – 10909 Redis Cluster Redis Cluster – Architecture slots 10910 – 16363 Availability Zone B Availability Zone C slots 5455 – 10909 slots 5455 – 10909slots 0 - 5454 slots 0 - 5454 slots 10910 – 16363 slots 10910 – 16363 Redis Cluster – Multi AZ A cluster consists of 1 to 15 shards example: 3 shard cluster, 2 read replicas
  • 19. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Availability Zone A slots 0 - 5454 Redis Cluster Redis Cluster – Architecture slots 10910 – 16363 Availability Zone B Availability Zone C slots 5455 – 10909 slots 5455 – 10909slots 0 - 5454 slots 0 - 5454 slots 10910 – 16363 Shard ReplicaReplicaPrimary Each shard has a Primary Node and up to 5 replica nodes slots 5455 – 10909 slots 10910 – 16363
  • 20. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Availability Zone A slots 0 - 5454 slots 5455 – 10909 Redis Cluster Redis Cluster – Architecture slots 10910 – 16363 Availability Zone B Availability Zone C slots 5455 – 10909 slots 5455 – 10909 Shard ReplicaReplica Primary Each shard has a Primary Node and up to 5 replica nodes slots 0 - 5454 slots 0 - 5454 slots 10910 – 16363 slots 10910 – 16363
  • 21. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Availability Zone A slots 0 - 5454 Redis Cluster Redis Cluster – Architecture slots 10910 – 16363 Availability Zone B Availability Zone C slots 10910 – 16363 slots 10910 – 16363 Shard Replica PrimaryReplica Each shard has a Primary Node and up to 5 replica nodes slots 5455 – 10909 slots 0 - 5454 slots 5455 – 10909 slots 0 - 5454 slots 5455 – 10909
  • 22. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Setting up Redis Cluster - Console Cluster Name
  • 23. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Setting up Redis Cluster - Console Redis Version
  • 24. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Setting up Redis Cluster - Console Instance
  • 25. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Setting up Redis Cluster - Console # of Shards
  • 26. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Setting up Redis Cluster - Console # of Replica’s
  • 27. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Slots Distribution Setting up Redis Cluster - Console
  • 28. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Select AZs Setting up Redis Cluster - Console
  • 29. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved ElastiCache for Redis Failure Scenarios “Everything fails, all the time.” GET quote:failureREDIS:6379> -- Werner Vogels, CTO Amazon.com --
  • 30. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Availability Zone A slots 0 - 5454 slots 5455 – 10909 Redis Cluster slots 10910 – 16363 Availability Zone B Availability Zone C slots 5455 – 10909 slots 5455 – 10909slots 0 - 5454 slots 0 - 5454 slots 10910 – 16363 slots 10910 – 16363 Scenario 1: Single Primary Failure
  • 31. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Availability Zone A slots 0 - 5454 slots 5455 – 10909 Redis Cluster Scenario 1: Single Primary Failure slots 10910 – 16363 Availability Zone B Availability Zone C slots 5455 – 10909 slots 5455 – 10909slots 0 - 5454 slots 0 - 5454 slots 10910 – 16363 Mitigation: 1. Automatic Failure Detection & Replica Promotion (~15-30s) 2. Repair Failed Node slots 10910 – 16363
  • 32. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Availability Zone A slots 0 - 5454 slots 5455 – 10909 Redis Cluster Scenario 2: Majority of Primaries Fail slots 10910 – 16363 Availability Zone B Availability Zone C slots 5455 – 10909 slots 5455 – 10909slots 0 - 5454 slots 0 - 5454 slots 10910 – 16363slots 10910 – 16363
  • 33. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Availability Zone A slots 0 - 5454 slots 5455 – 10909 Redis Cluster slots 10910 – 16363 Availability Zone B Availability Zone C slots 5455 – 10909 slots 5455 – 10909slots 0 - 5454 slots 0 - 5454 Mitigation: Redis enhancements on ElastiCache • Automatic Failure Detection and Replica Promotion • Repair Failed Nodes slots 10910 – 16363slots 10910 – 16363 Scenario 2: Majority of Primaries Fail
  • 34. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Feature Enabled Disabled FAILOVER 15-30s (NON-DNS) 1.5m-2m (DNS BASED) FAILOVER RISK • WRITES effected - Partial dataset (less risk with more partitions) • READS available • Writes effected on entire dataset. • READS available PERFORMANCE SCALES with cluster size (90 nodes – 15 primaries + 0-5 replicas per shard. 6 Nodes (1 Primary + 0-5 replicas) MAX CONNECTIONS • PRIMARIES (65K X 15 = 975,000) • REPLICAS (65K X 75 = 4,875,000) • PRIMARY: 65K • REPLICAS: (65K x 5 = 325,000) STORAGE 3.5TiB + 237GB COST Example: Assume workload needs 175GB Smaller nodes but more $$ 9 x cache.r3.xlarge (0.455hr) = $4.095hr 255.6 GB Larger nodes less $ 1 X cache.r3.8xlarge = $3.640 , 237 GB REDIS CLUSTER-MODE ENABLED VS DISABLED
  • 35. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved ElastiCache Best Practices
  • 36. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Cluster Sizing Best Practices • Storage – Clusters should have adequate Memory • Recommended: Memory needed + 25% reserved memory (for Redis) + some room for growth (optional 10%). • Optimize using eviction policies and TTLs • Scale up or out when before reaching max-memory using Cloudwatch alarms • Use memory optimized nodes for cost effectiveness • Performance – Performance should not be compromised • Benchmark operations using Redis Benchmark tool • For more READIOPS – Add Replicas • For more WRITEIOPS – Add shards (scale out) • For more Network IO – Use network optimized instances and scale out • Use pipelining for bulk reads/writes • Consider Big(O) time complexity for data structure commands • Cluster Isolation (apps sharing key space) – Chose a strategy that works for your workload • Identify what kind of isolation is needed based on the workload and environment • Isolation: No Isolation $ | Isolation by Purpose $$ | Full Isolation $$$
  • 37. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Redis Benchmark Tool Open source utility to benchmark performance • example: src/redis-benchmark -h r3-xlarge-perf.foio87.0001.use1.cache.amazonaws.com -p 6379 -n -150000 -d 100 Syntax: redis-benchmark -h <host> -p <port> -c 50 -n 1000 -d 500 –q -c <clients> - Specifies the number of parallel connections (default 50). -n <requests> - Specifies the number of requests (default 1000000). -d <size> - Specifies the data size of GET and SET values in bytes. -t <test1,test2> - Comma separated list of tests to perform. -q – Quiet operation, displays only the result.
  • 38. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Redis max-memory Policies Select a max-memory policy based on your workload needs • noeviction: return errors when the memory limit was reached and the client is trying to execute commands that could result in more memory to be used. • allkeys-lru: evict keys trying to remove the less recently used (LRU) keys first. • volatile-lru: evict keys trying to remove the less recently used (LRU) keys first, but only among keys that have an expire set. • allkeys-random: evict random keys in order to make space for the new data added. • volatile-random: evict random keys in order to make space for the new data added, but only evict keys with an expire set. • volatile-ttl: evict only keys with an expire set, and try to evict keys with a shorter time to live (TTL) first. The policies volatile-lru, volatile-random and volatile-ttl behave like noeviction if there are no keys to evict matching the prerequisites.
  • 39. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Architecting for Availability & Performance • Upgrade to the latest engine version – 3.2.4 • Set reserved-memory to 25-30% of total available memory • Swap usage should be zero or very low. Scale if not. • Put read-replicas in a different AZ from the primary • For important workloads use 2 read replicas per primary • Write to the primary, read from the read-replicas • Take snapshots from read-replicas • For Redis Cluster have odd number of shards. • Use newer Intel processors for best IO performance • Use Failover API to environment
  • 40. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Key ElastiCache CloudWatch Metrics • CPUUtilization • Memcached – up to 90% ok • Redis – divide by cores (ex: 90% / 4 = 22.5%) • SwapUsage low • CacheMisses / CacheHits Ratio low / stable • Evictions near zero • Exception: Russian doll caching • CurrConnections stable • Setup alarms with CloudWatch Metrics • Whitepaper: http://bit.ly/elasticache-whitepaper
  • 41. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved ElastiCache Modifiable Parameters – Maxclients: 65000 (unchangeable) • Use connection pooling • timeout – Closes a connection after its been idle for a given interval • tcp-keepalive – Detects dead peers given an interval – Databases: 16 (Default) • Logical partition – Reserved-memory: 0 (Default) • Recommended  50% of maxmemory to use before 2.8.22  25% after 2.8.22 – ElastiCache – Maxmemory-policy: • The eviction policy for keys when maximum memory usage is reached. • Possible values: volatile-lru, allkeys-lru, volatile-random, allkeys-random, volatile-ttl, noeviction
  • 42. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Common Usage Patterns Amazon ElastiCache
  • 43. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved
  • 44. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Usage Patterns Session Management Database Caching APIs (HTTP responses) IOT Streaming Data Analytics (Filtering/Aggregation) Pub/Sub Social Media (Sentiment Analysis) Standalone Database (Metadata Store) Leaderboards
  • 45. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Caching Clients Amazon ElastiCache Redis Amazon DynamoDB Elastic Load Balancing Amazon EC2 Amazon RDS write-through reads/ writes DDB streams mysql.lambda_async reads/ writes https://aws.amazon.com/caching/database-caching/ Amazon S3 reads/ writes Object data Unstructured data Relational data
  • 46. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Amazon EC2 reads/ writes Amazon ElastiCache Redis reads MongoDB Cluster DBObject doc = collection.findOne(); Cache Serialized DBObject in Redis (Good) Cache rows in Redis Hash (Faster/More efficient) Cassandra Cluster Amazon ElastiCache Redis Amazon EC2 reads/ writes reads ResultSet rs = session.execute(stmt); Cache Serialized ResultSet in Redis (Good) Cache rows in Redis Hash (Faster/More efficient) Caching NoSQL Databases with ElastiCache  Smaller NoSQL DB Clusters needed = Lower Costs  Faster Data Retrieval = Better Performance
  • 47. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved • 1) Install php, apache php memcache client • e.g. yum install php apache php-pecl-memcache • 2) Configure “php.ini” • session.save_handler = memcache • session.save_path= • "tcp://node1:11211, tcp://node2:11211" • 3) Configure “php.d/memcache.ini” • memcache.hash_strategy = consistent • memcache.allow_failover = 1 • memcache.session_redundancy=3* • 4) Restart httpd • 5) Begin using Session Data: Auto Scaling group • For situations where you need an external session store • Especially needed when using ASGs • Cache is optimal for high-volume reads PHP Example Session Caching https://github.com/mikelabib/elasticache-memcached-php-demo
  • 48. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Amazon Kinesis Analytics Amazon Kinesis Streams Amazon Kinesis Streams Amazon ElastiCache (Redis) cleansed stream Streaming Data Enrichment / Processing DataSources raw stream Subscribers Lambda Function 1 ContinualData Filtering/Enrichment Real-time Pub/Sub Lambda Function 2
  • 49. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Big Data Architectures using Redis Amazon Kinesis DataSources AWS Lambda Apache Storm on EMR Spark Streaming on EMR Amazon Kinesis App Amazon EC2 AWS IoT Amazon ElastiCache Collect Store Process Amazon S3 Apache Kafka AWS Lambda Custom App Spark on EMR Analyze
  • 50. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Rules Engine Amazon ElastiCache Redis AWS Lambda Direct Integration LambdaSNS SQS S3 KinesisDDB AWS IoT Devices AWS IoT Sensor Store IoT powered by ElastiCache
  • 51. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved IoT Demo – AWS IoT + Lambda + ElastiCache https://aws.amazon.com/blogs/database/managing-iot-and-time-series-data-with-amazon-elasticache-for-redis/
  • 52. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Mobile Apps Powered by ElastiCache Amazon API Gateway AWS Lambda Amazon ElastiCache Redis GEOADD GEORADIUS Search points of interest Update points of interest https://aws.amazon.com/blogs/database/amazon-elasticache-utilizing-redis-geospatial-capabilities/ Amazon DynamoDB DDB streams Amazon EC2
  • 53. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Ad Tech Clients Advertisers https://aws.amazon.com/caching/database-caching/ Ad Network Ad Slot Consumer Ad Slot Publishers Ad Placement (Websites/Apps) Amazon ElastiCache Redis <40 ms Clickstream (Shopping Events) User visits page Publisher places ad slot for auction Ad Network calls for bids Bidders respond with bids Winners bid Ad displayed
  • 54. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Chat Apps powered by ElastiCache https://aws.amazon.com/blogs/database/amazon-elasticache-utilizing-redis-geospatial-capabilities/ Clients Chat Apps Application Load Balancer WebSockets Amazon ElastiCache Redis PubSub Serverpersistent connections Elastic Beanstalk SUBSCRIBE chat_channel:114 PUBLISH chat_channel:114 "Hello all" >> ["message", "chat_channel:114", "Hello all"] UNSUBSCRIBE chat_channel:114
  • 55. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved • Very popular for gaming apps which 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 Gaming - Real-time Leaderboard
  • 56. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved • 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 Rate Limiting
  • 57. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved • 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 Recommendation Engine - Ratings INCR item:38927:likes HSET item:38927:ratings "Susan" 1 INCR item:38927:dislikes HSET item:38927:ratings "Tommy" -1
  • 58. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Database Caching Strategies
  • 59. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Web App RDS DB instancestandby (multi-AZ) MS SQL instance  Scalability  Durability Latency  Cost Auto Scaling Auto Scaling WHY CACHING
  • 60. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Web App RDS DB instancestandby (multi-AZ) MS SQL instance Auto Scaling Auto Scaling Scalability  Durability Latency  Cost WHY CACHING
  • 61. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Web App RDS DB instancestandby (multi-AZ) MS SQL instance  Scalability  Durability Latency Cost Auto Scaling Auto Scaling WHY CACHING
  • 62. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved App RDS DB instancestandby (multi-AZ) MS SQL instance  Scalability  Durability  Latency  Cost Auto Scaling Auto Scaling Web WHY CACHING
  • 63. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Caching - Patterns Cache-Aside - Lazy Loading Amazon ElastiCache Applications Amazon RDS 1 2 3 1.) Check Cache, if HIT return 2.) If Cache MISS 3.) Update Cache https://d0.awsstatic.com/whitepapers/Database/database-caching-strategies-using-redis.pdf
  • 64. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Caching - Patterns Cache-Aside - Write-Through Amazon ElastiCache Applications Amazon RDS 1 2 1.) Update Primary DB 2.) Update Cache https://d0.awsstatic.com/whitepapers/Database/database-caching-strategies-using-redis.pdf
  • 65. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Java App Java App Web Server Web Server Database Cache Customers AZ1 AZ2 Distributed Cache Example workload topology: Customer Data CustomerDB Primary CustomerDB Standby
  • 66. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Caching Strategies 1. Cache Database SQL ResultSet (Row) PRO When data retrieval logic is abstracted from the code consuming the ResultSet, caching the ROW can be extremely effective and can be implemented against any RDBMS. CON • Does not speed up processing time SELECT * FROM x WHERE y ID First_Name Last_Name City 123 Michael Labib Chicago ResultSet Object (ROW) Key: Query, Value: CRS as byte array
  • 67. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Caching Strategies 2. Cache database values into custom format in a Redis String SELECT * FROM x WHERE y ID First_Name Last_Name City 123 Michael Labib Chicago String firstName = rs.getString(First_Name) PRO Very easy to implement. Cache any desired database fields and values into a Redis String. For example, store your retrieved data into a JSON object stored in a Redis String. CON No JSON specific query support Key: 123, Value: ‘{ “firstname”: “Michael”, “lastname”: “Labib”, “city”: “Chicago” } ‘
  • 68. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Caching Strategies 3. Cache serialized application object (e.g. Java Object ) SELECT * FROM x WHERE y ID First_Name Last_Name City 123 Michael Labib Chicago Key: CUSTOMER_ID:123, Value: Customer Object as byte array String firstName = rs.getString(First_Name); customer.setFirstName(firstName); String lastName = rs.getString(Last_Name); customer.setLastName(lastName); PRO Utilize application objects in their native structure and data state when serialized. CON Advanced application development use case.
  • 69. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved Caching Strategies 4. Leverage advanced Redis Data Structures for cached data SELECT * FROM x WHERE y ID First_Name Last_Name City 123 Michael Labib Chicago Key: CUSTOMER_ID:123, Value: rsHash String firstName = rs.getString(First_Name); rsHash.put(“firstName", firstName); String lastName = rs.getString(Last_Name); rsHash.put(“lastName", lastName); jedis.hmset(“CUSTOMER_ID:123", rsHash); PRO In addition to reducing data retrieval latency, cache data into specific data structure that simplifies the data access pattern.
  • 70. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved aws.amazon.com/activate Everything and Anything Startups Need to Get Started on AWS