Skip to content

Redis HA with standalone

Interactive Diagram

새 탭 ↗
  • Background
    • To configure Redis as HA, you need a cluster or sentinel configuration
    • Cluster or sentinel configurations require a complex structure and at least 3 instances by default
  • Redis standalone HA configuration
    • Reviewing HA configuration using only a Redis standalone configuration
    • Reviewing side-car, envoy proxy, redis proxy, etc. for data sync between individual Redis instances
  • Redis Master-Master HA configuration approach
  • Reviewing whether replication is possible by configuring a sidecar on each Redis standalone service
    • Dynomite, Envoy etc.

Dynomite can implement various key-value pair storage engines similar to Amazon DynamoDB. It is currently usable with Redis, Memcached, etc. Dynomite supports multi-datacenter replication and has a design applied for high availability.

The ultimate goal of Dynomite is to enable high availability and cross-datacenter replication on storage engines that do not inherently provide such functionality.

Refer to the Dynomite GitHub Wiki https://github.com/Netflix/dynomite/wiki Amazon DynamoDB Docs https://docs.aws.amazon.com/ko_kr/amazondynamodb/latest/developerguide/Introduction.html

  • Replication Flow

    • Assuming an on-premise environment, Dynomite and the target storage engine run on the same node, and the client makes requests to Dynomite.
    • The request is proxied to the storage engine on the same node or to a Dynomite process running on another node.
    • When the request passes through the Dynomite node, the data is replicated and stored in the target storage.
    • Afterward, the client retrieves the data again through an API call to Dynomite or the storage.

Original figure: Netflix Dynomite wiki, Architecture (linked only, not embedded for licensing reasons)

Refer to the Dynomite Architecture https://github.com/Netflix/dynomite/wiki/Architecture

A configuration approach for ensuring high availability of the Redis standalone service provided in a Kubernetes environment : datacenter replication via a Dynomite sidecar

  • Redis Standalone + Dynomite Sidecar Deployment
    • Group each Redis Deployment into a component and create a service that can handle requests in common
    • The client makes requests to the common service.
    • The common service load-balances to each dynomite pod.
    • When a write operation is requested to a dynomite pod, it performs the write to the target redis and proxies it to the pod configured in the dynomite seed.
    • The dynomite that received the proxy request also performs the write to its own target redis | When dynomite makes requests to the target redis, it calls through the k8s service created for each redis (each service is omitted in the diagram below)
PlantUML Diagram
  • Redis Standalone + Dynomite Sidecar Deployment
...
spec:
# Redis Standalone
containers:
- name: redis-dyno-001
image: redis:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 6379
command:
- redis-server
- "/redis-master/redis.conf"
resources:
limits:
cpu: 500m
memory: 512Mi
requests:
cpu: 300m
memory: 256Mi
volumeMounts:
- name: shared-storage
mountPath: /data
- name: redis-config
mountPath: /redis-master
# Dynomite Sidecar
- name: dynomite
image: dynomitedb/dynomite
imagePullPolicy: IfNotPresent
securityContext:
runAsUser: 999
runAsGroup: 999
ports:
# Dynomite Listener
- containerPort: 8101
name: dyno
# Dynomite Client
- containerPort: 8102
name: dyno-client
# Dynomite Stats/admin
- containerPort: 22222
name: dyno-admin
args: ["dynomite", "-c", "/etc/dynomitedb/conf/dynomite.yaml"]
resources:
limits:
cpu: 500m
memory: 512Mi
requests:
cpu: 300m
memory: 256Mi
volumeMounts:
- name: dyno-config
mountPath: /etc/dynomitedb/conf
...
  • Dynomite target server and seed configuration details (dynomite.yaml)
dyn_o_mite:
datacenter: dc1
rack: rack1
dyn_listen: 0.0.0.0:8101
listen: 0.0.0.0:8102
dyn_seeds:
- redis-dyno-002:8101:rack2:dc2:0 # dynomite seed that becomes the proxy target
servers:
- redis-dyno-001:6379:1 # redis server that becomes the read/write target
tokens: '0'
data_store: 0
pem_key_file: /etc/dynomitedb/dynomite.pem
secure_server_option: none
read_consistency: DC_QUORUM # DC_ONE / DC_QUORUM
write_consistency: DC_QUORUM

Envoy is an L7 proxy and communication bus designed for large modern service-oriented architectures, and is used to configure a service mesh. Among its many features, we reviewed the approach for replication and ensuring high availability through request mirroring of the Redis Proxy.

Envoy can act as a Redis Proxy to split commands between instances in a cluster. In this mode, Envoy’s goal is to maintain availability and partition tolerance rather than consistency. It also supports routing commands to different upstream clusters from different workloads based on access patterns, eviction, or isolation requirements.

Refer to the Envoy Redis Proxy Overview https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/other_protocols/redis.html

  • Request Flow

    • The internal structure of the Envoy Redis Proxy can be broadly divided into Listener / Cluster.
    • The Listener defines the socket address for receiving requests, through which requests are received
    • Filters are defined inside the Listener to set the routing policy for requests
    • The above routing target can be set to one or more of the clusters defined in Envoy
    • In the case of the Redis Proxy, the target redis server / cluster can be defined in the cluster
  • HTTP router filter example Envoy request handling architecture: listener, filter chain, HTTP router filter and cluster Source: Envoy docs, Life of a Request, Envoy Project Authors, Apache-2.0

Refer to Envoy Life of a Request https://www.envoyproxy.io/docs/envoy/latest/intro/life_of_a_request#

A configuration approach for ensuring high availability of the Redis standalone service provided in a Kubernetes environment : request mirroring via an Envoy Redis Proxy sidecar

  • Redis Standalone + Envoy Sidecar Deployment
    • Group each Redis Deployment into a component and create a service that can handle requests in common
    • The client makes requests to the common service.
    • The common service load-balances to each envoy pod.
    • When a write operation is requested to an envoy pod, it writes to the routed redis.
    • It mirrors the request to another redis defined in the envoy cluster and writes to it. | When envoy writes to redis and mirrors requests, it calls through the k8s service created for each redis (each service is omitted in the diagram below)
PlantUML Diagram
  • Redis Standalone + Envoy Sidecar Deployment
...
spec:
# Redis Standalone
containers:
- name: redis-envoy-001
image: redis:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 6379
command:
- redis-server
- "/redis-master/redis.conf"
resources:
limits:
cpu: 500m
memory: 512Mi
requests:
cpu: 300m
memory: 256Mi
volumeMounts:
- name: shared-storage
mountPath: /data
- name: redis-config
mountPath: /redis-master
# Envoy Sidecar
- name: envoy
image: envoyproxy/envoy-dev:latest
imagePullPolicy: IfNotPresent
ports:
# Envoy Proxy
- containerPort: 6380
name: envoy
# Envoy Admin
- containerPort: 8001
name: admin
resources:
limits:
cpu: 500m
memory: 512Mi
requests:
cpu: 300m
memory: 256Mi
volumeMounts:
- name: envoy-config
mountPath: /etc/envoy
...
  • Envoy Listener/Filter and Cluster configuration details (envoy.yaml)
# Admin configuration
admin:
access_log_path: "/dev/null"
address:
socket_address:
address: 0.0.0.0
port_value: 8001
static_resources:
# Listener Port address configuration
listeners:
- name: redis_listener
address:
socket_address:
address: 0.0.0.0
port_value: 6380
filter_chains:
- filters:
# Proxy Filter type definition
- name: envoy.filters.network.redis_proxy
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.redis_proxy.v3.RedisProxy
prefix_routes:
# route target cluster definition
routes:
- cluster: redis-envoy-001
prefix: ""
# request mirroring target cluster definition
request_mirror_policy:
- cluster: redis-envoy-002
exclude_read_commands: true
stat_prefix: egress_redis
settings:
op_timeout: 5s
enable_redirection: true
# define the redis standalone service list in the target cluster
clusters:
- name: redis-envoy-001
connect_timeout: 0.25s
type: STRICT_DNS
lb_policy: MAGLEV
load_assignment:
cluster_name: redis-envoy-001
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: redis-envoy-001
port_value: 6379
- name: redis-envoy-002
connect_timeout: 0.25s
type: STRICT_DNS
lb_policy: MAGLEV
load_assignment:
cluster_name: redis-envoy-002
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: redis-envoy-002
port_value: 6379

When connecting to Redis through the proxy, only commands that can be reliably hashed to a server are supported, with AUTH and PING being exceptions. All other supported commands must have a key passed as a parameter, and they are functionally identical to the original Redis commands except for supported command failure scenarios.

For example, commands such as hello / info / keys are not supported, and delete-all commands that operate without parameters, such as flushall, are not supported. | In the case of Dynomite, the keys command is supported

~ redis-cli -p 6380
127.0.0.1:6380> keys *
(error) unsupported command 'keys'
127.0.0.1:6380> hello 3
(error) unsupported command 'hello'
127.0.0.1:6380> info dir
unsupported command 'info'
127.0.0.1:6380> flushall
(error) invalid request
...

Refer to Envoy Redis Proxy Supported Commands https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/other_protocols/redis.html#supported-commands

In the case of the Envoy Redis Proxy, it seems more suitable for distributed data processing such as partitioning / sharding than for maintaining consistency through datacenter replication

  • An approach for data distribution and providing read replicas via prefixes
PlantUML Diagram
  • Configuration details
...
static_resources:
listeners:
- name: redis_listener
address:
socket_address:
address: 0.0.0.0
port_value: 6380
filter_chains:
- filters:
- name: envoy.filters.network.redis_proxy
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.redis_proxy.v3.RedisProxy
prefix_routes:
routes:
# request mirroring per prefix
- cluster: redis-master
prefix: "departments"
request_mirror_policy:
- cluster: redis-departments
exclude_read_commands: true
- cluster: redis-master
prefix: "employees"
request_mirror_policy:
- cluster: redis-employees
exclude_read_commands: true
stat_prefix: egress_redis
settings:
op_timeout: 5s
enable_redirection: true
clusters:
- name: redis-master
connect_timeout: 0.25s
type: STRICT_DNS
lb_policy: MAGLEV
load_assignment:
cluster_name: redis-master
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: redis-master
port_value: 6379
- name: redis-departments
connect_timeout: 0.25s
type: STRICT_DNS
lb_policy: MAGLEV
load_assignment:
cluster_name: redis-departments
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: redis-departments
port_value: 6379
- name: redis-employees
connect_timeout: 0.25s
type: STRICT_DNS
lb_policy: MAGLEV
load_assignment:
cluster_name: redis-employees
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: redis-employees
port_value: 6379
...

It also supports proxies for MongoDB / Postgres, etc.

Comparing the baseline performance of Redis with the performance through the proxy.

A performance measurement tool that Redis itself provides for RedisCluster and Sentinel setups

  • Measured with AOF persistence
  • For storage, an NFS-based storage service that supports ReadWriteMany is used
CategoryValue
Redis CPU0.3 / 0.5
Reids Memory0.5Gi
StorageAmazon EBS (General Purpose)
Redis PersistenceAOF (everysec)

As a result of running the benchmark test through the proxy, the performance was measured to be reduced by about 50% compared to the baseline performance.
Since it generally appears capable of handling 10,000+ tps, it seems there will be no problem handling around 2,000~3,000 tps when used in an application.

  • Redis Benchmark
redis $ redis-benchmark -q -t get,set,lpop,lpush
SET: 20815.99 requests per second, p50=0.311 msec
GET: 20370.75 requests per second, p50=0.327 msec
LPUSH: 21781.75 requests per second, p50=0.303 msec
LPOP: 21810.25 requests per second, p50=0.295 msec
  • Dynomite Benchmark
dynomite $ redis-benchmark -p 8102 -q -t get,set,lpop,lpush
SET: 14830.19 requests per second, p50=0.887 msec
GET: 19623.23 requests per second, p50=0.583 msec
LPUSH: 14898.69 requests per second, p50=0.879 msec
LPOP: 14909.80 requests per second, p50=0.879 msec
  • Envoy Redis Proxy Benchmark
envoy $ redis-benchmark -p 6380 -q -t get,set,lpop,lpush
SET: 9100.01 requests per second, p50=0.767 msec
GET: 11132.14 requests per second, p50=0.727 msec
LPUSH: 9426.85 requests per second, p50=0.823 msec
LPOP: 9912.77 requests per second, p50=0.839 msec
  • Performed in an appropriate environment that yields performance of 1000+ TPS
  • 2 nGrinder Agents
CategoryValue
Spring CPU0.5 / 2
Spring Memory2048Mi
Redis CPU0.3 / 0.5
Reids Memory0.5Gi
StorageAmazon EBS (General Purpose)
Redis PersistenceAOF (everysec)
Ramp-UpEnable

Under the same load conditions, it appears that processing of around 1000 tps can be handled normally through the Sidecar Proxy.

When comparing Dynomite vs Envoy, the data sync results show no anomalies in either, and although the test results suggest that Dynomite’s replication method is slightly superior, the difference is not expected to be significant.

  • Redis Write Only
vUserThresholdTPSCountSyncComment
10002min1063115000-
20002min1089117000-
30002min78481000-Application performance degradation range (cpu max)
  • Dynomite Sidecar Replication
vUserThresholdTPSCountSyncComment
10002min1038114000100%
20002min86592000100%
30002min1138120000100%Application performance degradation range (cpu max)
  • Envoy Proxy Request Mirroring
vUserThresholdTPSCountSyncComment
10002min1054114000100%
20002min65069000100%
30002min67771000100%Application performance degradation range (cpu max)