Using Redis on Cloud? Here are Ten things You Should Know
This blog covers a range of Redis related best practices, tips and tricks including cluster scalability, client side configuration, integration, metrics and more.
2. After scaling your cluster, you better use those replicas!
3. Be mindful of consistency characteristics when using read replicas
4. Remember, you can influence how your keys are distributed across a Redis cluster
5. Did you think about scaling (back) in?
7. Unable to connect to Redis, help!
8. Redis 6 comes with Access Control Lists - use them!
9. There are things you cannot do (and that's ok)
This is not meant to be an exhaustive list by any means. I simply chose ten since it's a nice, wholesome number!
- Scaling Up (Vertical) - You can increase the capacity of individual nodes/instances for e.g. upgrade from Amazon EC2
db.r6g.xlarge
type todb.r6g.2xlarge
- Scaling Out (Horizontal) - You can add more nodes to the cluster
MemoryDB
) or a non-clustered primary-replica mode as in the case of ElastiCache with cluster mode disabled.This has the added benefit of increasing the overall high availability as well.
redis-cli
) is to redirect all reads to the primary node. If you've have added read replicas to scale read traffic, they are going to sit idle!RouteByLatency
or RouteRandomly
, both of which automatically turn on ReadOnly
mode.You can refer to how this works for Java clients such as Lettuce
MemoryDB
, the reads from primary nodes are strongly consistent. This is because the client application receives a successful write acknowledgement only after a write (to the primary node) is written to a durable Multi-AZ Transaction Log.16384
slots in total, a range of hash slots is assigned to each primary node in the cluster and each key belongs to a specific hash slot (thereby assigned to a particular node). Multi-key operations executed on a Redis cluster cannot work if keys belong to different hash slots.42
in a HASH
named customer:42:orders
and the customer profile info in customer:42:profile
, you can use curly braces {}
to define the specific substring which will be hashed. In this case, our keys are {customer:42}:orders
and {customer:42}:profile
- {customer:42}
now drives the hash slot placement. Now we can be confident that both these keys will in the same hash slot (hence same node).- Is there enough free memory on each of the nodes?
- Can this be done during non-peak hours?
- How will it affect your client applications?
- Which metrics can you monitor during this phase? (e.g.
CPUUtilization
,CurrConnections
etc.)
- Have you tested how your application/service behavior in face of failures? If not, please do! With MemoryDB and ElastiCache for Redis, you can leverage the Failover API to simulate a primary node failure and trigger a failover.
- Do you have replica nodes? If all you have is one shard with a single primary node, you are certainly going to have downtime if that node fails.
- Do you have multiple shards? If all you have is one shard (with primary and replica), in case of primary node failure of that shard, the cluster cannot accept any writes.
- Do your shards span multiple availability zones? If you have shards across multiple AZs, you will be better prepared to tackle AZ failure.
In all cases,MemoryDB
ensures that no data is lost during node replacements or failover
Tl;DR: It's probably the networking/security configuration
MemoryDB
and ElastiCache
, your Redis nodes are in a VPC. If you have a client application deployed to a compute service such as AWS Lambda, Amazon EKS, ECS, Amazon App Runner etc., you need to ensure you have the right configuration - specifically in terms of VPC and Security Group(s).MemoryDB
is Redis 6 compliant and supports ACL. However, to comply with older Redis versions, it configures a default user per account (with username default) and an immutable ACL called open-access
. If you create a MemoryDB
cluster and associate it with this ACL:- Clients can connect without authentication
- Clients can execute any command on any key (no permission or authorization either)
- Define an explicit ACL
- Add users (along with passwords), and
- Configure access strings as per your security requirements.
MemoryDB
gives you the total number of failed authenticate attempts - set an alarm on this to detect unauthorized access attempts.Don't forget perimeter security
TLS
on the server, don't forget to use that in your client as well! For example, using Go Redis:Not using it can give your errors that's not obvious enough (e.g. a generici/o timeout
) and make things hard to debug - this is something you need to be careful about.
MemoryDB
or ElastiCache
restrict access to some of the Redis commands. For example, you cannot use a subset of the CLUSTER related commands since the cluster management (scale, sharding etc.) is taken of by the service itself.latency-monitor-threshold
using CONFIG SET, you can set the slowlog-log-slower-than
setting in the parameter group and then use slowlog get
to compare against it.CurrConnections
: the number of client connections (excluding ones from read replicas)NewConnections
: the total number of connections that have been accepted by the server during a specific period.
MemoryDB
or Elasticache
cluster mode enabled), you need to use NewClusterClient (not NewClient):Interestingly enough, there is UniversalClient option which is a bit more flexible (at the time of writing, this is in Go Redis v9)
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.