Metarank supports two possible persistence modes:
Persistence mode is configured by the optional
statesection in the configuration file. By default, if the section is not defined, Metarank uses memory persistence.
Memory persistence is no persistence at all: the complete Metarank state is stored only in RAM, is ephemeral, and will be entirely lost on each service restart.
Nevertheless, memory persistence can be useful:
- As a staging env to validate configuration changes before going to production.
To configure memory persistence, use the
Metarank can use Redis 6+ as a persistence method. To enable it, use the following config file snippet:
format: binary # optional, default=binary, possible values: json, binary
cache: # optional
maxSize: 1024 # size of in-memory client-side cache for hot keys, optional, default=1024
ttl: 1h # how long should key-values should be cached, optional, default=1h
pipeline: # optional
maxSize: 128 # batch write buffer size, optional, default=128
flushPeriod: 1s # buffer flush interval, optional, default=1s
enabled: true # toggle pipelining, optional, default=true
auth: # optional
user: <username> # optional when Redis ACL is disabled
password: <password> # required if Redis server is run with requirepass argument
tls: # optional, defaults to disabled
enabled: true # optional, defaults to false
ca: <path/to/ca.crt> # optional path to the CA used to generate the cert, defaults to the default keychain
verify: full # optional, default=full, possible values: full, ca, off
# full - verify both certificate and hostname
# ca - verify only certificate
# off - skip verification
timeout: # optional, defaults to 1s for all sub-timeouts
connect: 1s # optional, defaults to 1s
socket: 1s # optional, defaults to 1s
command: 1s # optional, defaults to 1s
Redis persistence is sensitive to network latencies (as it needs to perform a couple of round-trips on each event), hence Metarank leverages a couple of Redis performance optimization strategies:
A note on optional cache & pipelining related settings:
- Metarank has a separate cache per underlying feature type (like scalar/counter/map/etc, 10 total), so
cache.maxSizeis set per cache type, so keep in mind an implicit multiplication: default value
1024in reality means
cache.ttldefines expiration interval after last read, so hot features may be cached almost indefinitely. The problem of stale cache values is solved with server-assisted invalidation: Redis server sends a notification to Metarank when key value was changed by someone else.
128is usually giving no benefit on low latencies (e.g. when Redis server is located in the same datacenter/AZ)
pipeline.flushPeriodcontrols the level of "eventualness" in the overall eventual consistency. With values larger than
10seconds, a second Metarank instance may not see write buffered in a first instance.
Metarank supports connecting to Redis using TLS for transport encryption, but there is no way to autodetect the type of connection.
To connect to a TLS-enabled Redis server with self-signed certificate, you need to specify the CA used to sign the certificate (for self-signed certs it will be the server certificate itself):
To connect to a TLS-enabled Redis server with a certificate generated with default CA (for example, AWS ElastiCache Redis), then you don't need to specify any custom CA:
In a case when you have cert trust issues connecting to a TLS-enabled redis, you can downgrade the verification level. Supported levels are:
full- verify both certificate and hostname
ca- verify only the certificate
off- skip verification, trust all
auth.passwordcan control the credentials used to connect to Redis. As hardcoding the credentials into the config file is not usually considered secure, you can supply the credentials from environment variables:
METARANK_REDIS_USER- only needed when Redis ACL is enabled.
METARANK_REDIS_PASSWORD- the pre-shared password used to connect to the Redis instance.
Metarank's Helm chart has a placeholder for the env variables passed inside the container inside Kubernetes. Usage example:
- name: METARANK_REDIS_PASSWORD
Metarank Redis persistence supports
binaryencoding formats for data stored in Redis:
json: focused on readability and debugging simplicity.
binary: low-overhead binary encoding format, with better performance and smaller memory footprint.
binaryformat on typical datasets (like RankLens) is ~2x faster and takes ~4x less RAM. We recommend it for larger datasets, when memory usage and associated costs are an important factor.
- Metarank requires Redis 6+ due to a lack of client-side caching support in 5.x
- you can disable client caching altogether (for example, for managed Redis-compatible engines, like GCP Memorystore Redis) with