Database Specialty - Elasticache/Memcached/Redis Flashcards
Memcached Overview
- Simple in-memory key-value store with sub-millisecond latency
- Automatic detection and recovery from cache node failures
- Typical applications
- Session store (persistent as well as transient session data store)
- DB query results caching (relational or NoSQL DBs – RDS / DynamoDB etc.)
- Webpage caching
- API caching
- Object caching (images / files / metadata)
- Well suited for web / mobile apps, gaming, IoT, ad-tech, and e- commerce
Memcached Architecture
- Memcached cluster is generally placed in private subnet
- Accessed from EC2 instance placed in a public subnet in a VPC
- Allows access only from EC2 network (apps should be hosted on whitelisted EC2 instances)
- Whitelist using security groups
- Up to 20 nodes per cluster
- Data is distributed across the available nodes
- Replicas are not supported
- Node failure = data loss
- Nodes can be deployed as Multi-AZ (to reduce
data loss)
Memcached Auto Discovery
- Allows client to automatically identify
nodes in your Memcached cluster - No need to manually connect to individual
nodes - Simply connect to any one node (using
configuration endpoint) and retrieve a list
of all other nodes - The metadata (list of all nodes) gets updated
dynamically as you add / remove nodes - Node failures are automatically detected, and nodes get replaced
- Enabled by default (you must use Auto
Discovery capable client)
Memcached Scaling
- Vertical scaling not supported
- can resize by creating a new cluster and
migrating your application - Horizontal scaling
- allows you to partition your data across
multiple nodes - up to 20 nodes per cluster and 100 nodes
per region (soft limit) - no need to change endpoints post scaling
(if you use auto-discovery) - must re-map at least some of your
keyspace post scaling (evenly spread cache
keys across all nodes)
Choosing between Redis and Memcached
Redis
* Sub-millisecond latency
* Supports complex data types (sorted sets,
hashes, bitmaps, hyperloglog, geospatial index)
* Multi AZ with Auto-Failover, supports sharding
* Read Replicas for scalability and HA
* Data Durability using AOF persistence
* Backup and restore features
Memcached
* Sub-millisecond latency
* Support only simple data types (string,
objects)
* Multi-node for sharding
* Non-persistent
* No backup and restore
* Multi-threaded architecture
ElastiCache Security – Encryption
- Memcached does not support encryption
- Encryption at rest for Redis (using KMS)
- Encryption in-transit for Redis (using TLS / SSL)
- Between server and client
- Is an optional feature
- Can have some performance impact
- Supports encrypted replication
- Redis snapshots in S3 use S3’s encryption
capabilities
ElastiCache Security – Auth and Access Control
- Authentication into the cache
- Redis AUTH – server can authenticate
the clients (requires SSL/TLS enabled) - Server Authentication – clients can
authenticate that they are connecting to
the right server
- Redis AUTH – server can authenticate
- IAM
- IAM policies can be used for AWS API-level
security (create cache, update cache
etc.) - ElastiCache doesn’t support IAM
permissions for actions within ElastiCache
(which clients can access what)
- IAM policies can be used for AWS API-level
ElastiCache Security – Network
- Recommended to use private subnets
- Control network access to ElastiCache
through VPC security groups - ElastiCache Security Groups - allows to
control access to ElastiCache clusters
running outside Amazon VPC - For clusters within Amazon VPC, simply
use VPC security groups
ElastiCache Logging and Monitoring
- Integrated with CloudWatch
- Host level metrics – CPU / memory /
network - Redis metrics – replication lag / engine
CPU utilization / metrics from Redis INFO
command - 60-second granularity
- Host level metrics – CPU / memory /
- ElastiCache Events
- Integrated with SNS
- Log of events related to cluster instances
/ SGs / PGs - Available within ElastiCache console
- API calls logged with CloudTrail
ElastiCache Pricing
- Priced per node-hour consumed for each node type
- Partial node-hours consumed are billed as full hours
- Can use reserved nodes for upfront discounts (1-3 year terms)
- Data transfer
- No charge for data transfer between EC2
and ElastiCache within AZ - All other data transfer chargeable
- No charge for data transfer between EC2
- Backup storage
- For automated and manual snapshots
(per GB per month) - Space for one snapshot is complimentary
for each active Redis cluster
- For automated and manual snapshots