More Related Content Similar to ElastiCache and Redis (20) More from Amazon Web Services (20) ElastiCache and Redis1. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Amazon ElastiCache and Redis
Michael Labib
mlabib@amazon.com
Sr In-Memory NoSQL Solutions Architect
2. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved
In-memory key-value store supporting
• Redis 3.2.10
• Memcached 1.4.34
High-performance
Fully managed; zero admin
Highly available and reliable
Hardened by Amazon
Amazon
ElastiCache
3. © 2018, 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
Service
Amazon
DynamoDB
Amazon
ElastiCache
and Amazon
DynamoDB
Accelerator
(DAX)
HDFS
4. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Powerful
~200 commands + Lua scripting
In-memory data structure server
Utility data structures
Strings, lists, hashes, sets, sorted sets,
bitmaps, and HyperLogLogs
Simple
Atomic operations
supports transactions
Ridiculously fast!
<1 ms latency for most commands
Highly available
replication
Persistence
Open source
Redis overview
5. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved
But wait, there’s more!
Run Lua scripts Geospatial queries Pub/sub
6. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved
SMEMBERS features
REDIS:6379>
Amazon
ElastiCache
1) “Easy to deploy & monitor”
AWS
Config
Amazon
CloudWatch
AWS
CloudTrail
AWS
CloudFormation
AWS
Management
Console
AWS CLI
and SDKs
alarm
REDIS:6379>
hget feature:details “deploy-monitor”
Amazon
SNS
Email
Notification
AWS
Lambda
7. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved
SMEMBERS features
REDIS:6379>
REDIS:6379>
hget feature:details “enhancements”
2) “Enhanced Redis Engine”
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
Amazon
ElastiCache
8. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved
SMEMBERS ec-team:open-source:contributorsREDIS:6379>
https://raw.githubusercontent.com/antirez/redis/2.8/00-RELEASENOTES
(from https://github.com/antirez/redis/issues/1814)
1) “Kevin McGehee”
2) “Qu Chen”
3) “Rajib Dugar”
hgetall ec-team:open-source:contributionsREDIS:6379>
1) PSYNC2 (Redis 4.0)
https://raw.githubusercontent.com/antirez/redis/4.0/00-RELEASENOTES
3) BGSAVE (Redis 3.2)
https://raw.githubusercontent.com/antirez/redis/3.2/00-RELEASENOTES
5) MIGRATE (Redis 3.0)
7) MASTER TIMEOUT (Redis 2.8)
https://raw.githubusercontent.com/antirez/redis/3.0/00-RELEASENOTES
https://raw.githubusercontent.com/antirez/redis/2.8/00-RELEASENOTES
9) INCREASE 2Billion+ KEYS in a DATASET (Redis 2.8)
2)
4)
6)
8)
10)
Amazon
ElastiCache
11) also: 4114, 4250, 3926, 3899
9. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Slot 0-5461
Cluster Mode Disabled
Keyspace
Slot 10923-16383
I Primary 0–5 Replicas
Cluster Mode Enabled
Primary Endpoint
1–15 Primaries/Shards
Slot 0
Slot 5462-10922
Slot 16383
Keyspace
0–5 Replicas
Configuration Endpoint
Slot 1 …
Vertically Scaled
Horizontally Scaled
Max Storage 407 GiB
Max Storage 6+ TiB
Redis topologies
10. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved
S5
S1
S2
S4 S3
Client
16384 hash slots per cluster
Slot for a key is CRC16(key) mod 16384
Slots are distributed across the cluster into shards
Developers must use a Redis cluster aware 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
Redis cluster: automatic client -side sharding
11. © 2018, 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
12. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Availability Zone A
slots 0–5454
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
Shard
ReplicaReplicaPrimary
Each shard has a primary node
and up to five replica nodes
slots 5455–10909
slots 10910–16363
Redis cluster—architecture
13. © 2018, 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–10909
Shard
ReplicaReplica Primary
Each shard has a primary node
and up to five replica nodes
slots 0–5454 slots 0–5454
slots 10910–16363
slots 10910–16363
Redis cluster—architecture
14. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Availability Zone A
slots 0–5454
Redis Cluster
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 five replica nodes
slots 5455–10909 slots 0–5454
slots 5455–10909
slots 0–5454 slots 5455–10909
Redis cluster—architecture
15. © 2018, 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
16. © 2018, 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
Mitigation:
1. Automatic failure detection and replica promotion (~15–30 s)
2. Repair failed node
slots 10910–16363
Scenario 1: Single primary failure
17. © 2018, 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–16363slots 10910–16363
Scenario 2: Multiple primary failures
18. © 2018, 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: Multiple primary failures
19. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved
0-5461
Shard 1 Shard 2 Shard 3
5462--10922 10923-16383
aws elasticache modify-replication-group-shard-configuration --replication-group-id rep-group-id
--apply-immediately --node-group-count 5
Simple API
Scale In || Out
Online Re-Sharding—zero downtime
20. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved
0-5461
reads/writes
Shard 1 Shard 2 Shard 3
Shard 4 Shard 5
5462--10922 10923-163830-2909,
5095-5461
5462-5783,
6876-9830
10923-14199
2910-5094,
9831--10922
No application interruption
Uniform slot distribution across shards
5784-6875,
14200-16383
Online Re-Sharding—zero downtime: Scale Out
21. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved
0-5461
reads/writes
Shard 1 Shard 2 Shard 3
Shard 4 Shard 5
5462--10922 10923-16383
Uniform slot distribution across shards
No Application Interruption
Online Re-Sharding—zero downtime: Scale In
22. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved
AWS Lambda
3 Shards
…
var params = {
ApplyImmediately: true,
NodeGroupCount: 5,
ReplicationGroupId: ‘rep-group-id’,
… }
elasticache.modifyReplicationGroupShardConfiguration(params, function(err, data) {
if (err) console.log(err, err.stack);
else console.log(data);
}); …
5 Shards
MEMORY
HIGH!
Amazon
CloudWatch
Cluster Resized
AWS SNS
Online Re-Sharding—CW alarm triggered
23. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Encryption
• In-Transit: encrypt all communications between clients
and Redis server as well as between nodes
• At-Rest: encrypt backups on disk and in Amazon S3
• Fully managed: setup via API or console, automatic
issuance and renewal
Compliance
• HIPAA eligibility for ElastiCache for Redis
• Included in AWS Business Associate Addendum
• Redis 3.2.6
Amazon ElastiCache Encryption and Compliance
24. © 2018, 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
Amazon
S3
reads/writes
Object data
Unstructured data
Relational data
25. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Caching NoSQL
Amazon
EC2 reads/
writes
reads
MongoDB
Cluster
Cassandra
Cluster
Smaller NoSQL DB clusters needed = lower costs
Faster data retrieval = better performance
Elasticsearch
Cluster
Clients
26. © 2018, 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
AWS Lambda function 1
Continual data
filtering/enrichment
Real-time
pub/sub
AWS Lambda function 2
27. © 2018, 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 Amazon EMR
Amazon
Kinesis app
Amazon
EC2
AWS IoT
Amazon
ElastiCache
Collect
Store
Process
Amazon
S3
Apache Kafka
AWS
Lambda
Custom
app
Spark on
Amazon
EMR
Analyze
28. © 2018, 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
29. © 2018, 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
30. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Ad tech powered by ElastiCache
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 bidsBidders respond
with bids
Winners bid
ad displayed
31. © 2018, 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
32. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved
• Very popular for gaming apps that need
uniqueness and 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 leaderboards
33. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Ex: throttling requests to an API
uses 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
34. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Amazon
ElastiCache
µs is the new ms
35. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved
aws.amazon.com/activate
Everything and Anything Startups
Need to Get Started on AWS