A second Redis instance kept as a read replica substitute, a regional mirror or a warm standby
drifts from the authoritative instance the moment a mirroring job fails or a write path misses it.
Reads served from the mirror then return a stale value or no value at all. Both instances answer
PING happily, both report healthy memory, so nothing flags it. The first symptom is a cache miss
storm or a customer seeing an old price.
This blueprint diffs a bounded key namespace between the two instances and repairs the secondary.
It reads each side with one read-only Lua script that returns every matching key with its type,
its remaining TTL and a SHA1 digest of its value, so a value never has to travel through a log to
be compared. Behind a dry run and a Pause it copies the missing and stale keys from the source,
deletes the orphans, then reads both instances again and fails the run if anything still differs.
This blueprint was created by zkasuran.
Safety
Neither Redis instance is authoritative by nature. One of them has to be designated. Getting
that backwards would overwrite good data with drifted data, which is worse than the drift. So the
flow refuses to guess: designated_source_of_truth must spell out the source host and port. A
mismatch or a blank value fails the run before a single key is read. The two instance input
groups must also point at different instances.
The source of truth has no write path at all.
- It is read with
EVAL_RO, so the server rejects a write from that script even if the script
were edited. On Redis 7 a write inside EVAL_RO answers
ERR Write commands are not allowed from read-only scripts.
- The only other task pointed at it is
read_from_source (io.kestra.plugin.redis.string.Get),
which issues GET.
- Every write task (
io.kestra.plugin.redis.string.Set,
io.kestra.plugin.redis.string.Delete) takes mirror_url. There is no task in the flow where a
write verb meets the source connection.
TTLs are carried, not dropped. Copying a volatile key without its expiry would silently turn it
permanent, so the audit reads the remaining TTL next to the value and the repair writes it back:
a volatile key is set with expirationDate, a persistent key is set without one, which also
clears an expiry the secondary should not have had. A key whose bytes match on both sides but
whose expiry does not is reported as TTL_DRIFT and repaired the same way.
Findings
| Finding |
Meaning |
Fix |
MISSING |
The source has the key, the secondary does not |
SET it on the secondary with the source TTL |
STALE |
Both have it, the value digests differ |
SET the source value on the secondary |
TTL_DRIFT |
Same bytes, different expiry beyond ttl_tolerance_seconds |
SET it again with the source expiry |
ORPHAN |
The secondary has a key the source does not |
DEL it on the secondary |
UNSUPPORTED |
The key is not a plain string on one of the sides |
Reported, never touched |
The namespace is read with SCAN inside the script, with the cursor drained before anything is
compared. A partial keyset is never used: if either instance holds more than max_keys matching
keys the run fails without diffing, because a truncated source keyset would report live keys as
orphans and the repair would delete them.
How it works
designation_gate (io.kestra.plugin.core.flow.If) checks that
designated_source_of_truth equals source_host:source_port and that the two instances are
not the same one. Otherwise not_designated fails the run and nothing is read.
source_read and mirror_read (io.kestra.plugin.redis.cli.RedisCLI) each run one EVAL_RO
script that scans the namespace, sorts the keys and returns key type ttl sha1 bytes per line.
parse turns both outputs into records. bounds_gate fails the run if either side reported the
namespace overflowing max_keys.
diff classifies every key in the union of the two keysets. plan splits the result into keys
to copy, orphans to delete and unsupported keys to leave alone. summary logs the findings.
route (io.kestra.plugin.core.flow.If):
- in sync:
in_sync logs it, nothing to do.
- drift:
alert posts to Slack.
remediate_gate runs only when auto_remediate is true and dry_run is false, otherwise
report_only records that nothing was touched.
hold (io.kestra.plugin.core.flow.Pause) waits for an answer. Without one, nothing is written.
- On approval
delete_orphans (io.kestra.plugin.redis.string.Delete) removes the orphans,
then remediate_copies (io.kestra.plugin.core.flow.Loop, concurrencyLimit: 1) reads each
key from the source with io.kestra.plugin.redis.string.Get and writes it to the secondary
with io.kestra.plugin.redis.string.Set, with or without a TTL.
reverify_source_read plus reverify_mirror_read read both instances again,
reverify_diff repeats the comparison and verify_result fails the run if any divergence
is left.
errors posts to Slack when the flow fails.
What you get
- A key level diff between two live Redis instances, with one of them designated as the source of
truth and the other the only one written to.
- Four kinds of divergence named per key, including the expiry drift that a value only comparison
misses.
- A repair that carries TTLs, runs one key at a time, sits behind two flags plus a human answer,
then proves itself with a second read of both instances.
Who it's for
- Teams running a second Redis as a regional mirror, a warm standby or a read replica substitute
fed by their own mirroring job.
- SREs who have served a stale value from a mirror and found out from a user.
- Anyone migrating between Redis instances who needs to know the target matches the source before
cutting traffic over.
Why orchestrate this with Kestra
The drift spans two systems that each look healthy on their own, so nothing reports it. Kestra
reads both instances the same way, holds the designation as a required input, sends the diff to
Slack, writes only behind auto_remediate, dry_run and a Pause, verifies the result against the
instances themselves and keeps the history of every reconcile.
Tested end to end
On Kestra 2.0.5 OSS against two Redis 7 instances on one Docker network, w34-redisx-src as the
designated source of truth and w34-redisx-dst as the secondary, with a local HTTP sink standing
in for Slack. The source held 6 string keys under mir:, two of them volatile (mir:e at 3600s,
mir:f at 7200s). The secondary was degraded in all four divergence classes across five keys:
mir:c absent (MISSING), mir:e absent while volatile on the source (MISSING with a TTL to
carry), mir:d holding a different value (STALE), mir:f holding the same bytes with no expiry
(TTL_DRIFT) plus mir:z present only there (ORPHAN).
| Run |
Inputs |
Result |
| 1 |
defaults, degraded secondary |
5 divergences: MISSING mir:c, STALE mir:d, MISSING mir:e ttl=3586, TTL_DRIFT mir:f ttl=7186, ORPHAN mir:z. Alert sent, nothing changed, confirmed with redis-cli on both instances |
| 2 |
auto_remediate: true, dry_run: true |
Same 5 divergences, gate stayed closed, report_only logged, no key changed |
| 3 |
auto_remediate: true, dry_run: false, Pause resumed with approved: false |
declined logged. redis-cli on the secondary byte identical to before runs 2 and 3 |
| 4 |
auto_remediate: true, dry_run: false, Pause resumed with approved: true |
Copied 4 keys, deleted 1 orphan, re-read reported 0 divergence. redis-cli on the secondary then held exactly the 6 source keys at the same digests, with mir:e carrying ttl 3485 against the source 3478 and mir:f carrying ttl 7085 where it had none |
| 5 |
clean secondary, defaults |
0 divergences, in_sync branch, no alert |
| 6 |
designation transposed to the secondary, auto_remediate: true, dry_run: false |
not_designated failed the run before either instance was read, errors posted to Slack |
| 7 |
max_keys: 2, auto_remediate: true, dry_run: false |
namespace_too_large failed the run after the reads, before the diff. Nothing compared, nothing changed |
| 8 |
approved, with a writer setting a new value for the in sync key mir:a on the secondary during the Pause |
The repair fixed its 4 planned keys, then the second read found STALE mir:a, which was never in the plan. verify_result failed the run instead of reporting success |
| 9 |
unreachable source host |
source_read failed, the run failed, the errors block posted to Slack |
| 10 |
approved, with a hash key mir:h added to the source namespace |
Reported as UNSUPPORTED and left alone: 4 copies, 1 delete, run SUCCESS. EXISTS mir:h on the secondary returned 0 |
Source of truth untouched: its 6 keys, their types, their value digests and their byte lengths were
identical before and after the full remediation in run 4, read straight from redis-cli on the
source, with only its own TTL countdown moving. A write attempted through EVAL_RO against it was
refused by the server with ERR Write commands are not allowed from read-only scripts.
Detector proof: the same pair reported 5 divergences degraded and 0 when in sync, both matching what
redis-cli showed key by key. Four separate runs failed on purpose: a transposed designation, an
oversized namespace, a concurrent writer caught by the re-verify, plus an unreachable instance.
Prerequisites
- Two reachable Redis 7+ instances (for
EVAL_RO), one designated as the source of truth.
- String keys under a namespace narrow enough to read in one run. A key that is a hash, a list, a
set or a stream is reported and left alone.
- For the audit, a user on each instance allowed to run
EVAL_RO, SCAN, TYPE, GET and
PTTL. For the repair, a user on the secondary allowed to run SET and DEL. The source needs
no write rights at all, which is the posture to grant it.
- Local testing:
docker run -d --name src --network kw7 redis:7-alpine redis-server --save '';
docker run -d --name dst --network kw7 redis:7-alpine redis-server --save '';
- seed a few keys on the source, copy most of them to the destination, then leave one out, change
one value, drop one expiry and add one key the source does not have.
Secrets
REDIS_SOURCE_PASSWORD: password for the source of truth, read by the audit tasks.
REDIS_MIRROR_PASSWORD: password for the secondary, read by the audit plus the repair tasks.
SLACK_WEBHOOK_URL: used by alert and the errors block.
- In Kestra OSS, provide each one as a base64 encoded environment variable prefixed
SECRET_.
Inputs
| Input |
Default |
Purpose |
source_host / source_port |
localhost, 6379 |
The instance that is only read |
source_password |
secret('REDIS_SOURCE_PASSWORD') |
Source password |
mirror_host / mirror_port |
localhost, 6380 |
The secondary, the only instance written to |
mirror_password |
secret('REDIS_MIRROR_PASSWORD') |
Secondary password |
designated_source_of_truth |
empty |
Must equal source_host:source_port or the run refuses |
key_pattern |
mirror:* |
The namespace to reconcile |
max_keys |
1000 |
Namespace ceiling, over it the run fails without diffing |
ttl_tolerance_seconds |
60 |
How far two expiries may differ before it counts as drift |
network |
empty |
Docker network for the redis-cli container |
approval_timeout |
PT1H |
How long the Pause waits |
auto_remediate |
false |
Allow writes to the secondary |
dry_run |
true |
Must be false for a change to apply |
Quick start
- Add the
REDIS_SOURCE_PASSWORD, REDIS_MIRROR_PASSWORD plus SLACK_WEBHOOK_URL secrets.
- Import the flow, point the two instance input groups at your instances, set
key_pattern to one
namespace and set designated_source_of_truth to the source host and port.
- Run it once and read the findings.
- Run it with
auto_remediate: true and dry_run: false, answer the Pause, then read the
reconciled log for the proof.
- Enable the
hourly trigger, which always runs in safe mode.
How to extend
- Reconcile a namespace too large for one run by passing a cursor between runs in a KV store and
reconciling one slice per execution.
- Add hash keys by returning a digest of the sorted field list from the script and repairing with
HSET.
- Fan out to several mirrors by looping over a list of secondary hosts, each diffed against the one
designated source.
- Make the diff report only, by setting
auto_remediate to false on a schedule, then feed the
findings into a dashboard.
Links