Engineering blog · Self-healing architecture

An autonomous recovery loop that closes on its own

Veritas runs a closed loop on every cluster it watches: observe a continuous signal, diagnose by correlating that signal across quorum, replication, and lease state, act on a risk-scored remediation plan, and verifywith a real end-to-end probe — never a heartbeat. The plan below maps each step of the loop to a concrete failure mode and shows what closes the incident instead of leaving it open.

Three failure modes the loop has to close
Scenario A
Replication-lag drift under the threshold

Patroni watches a configurable lag threshold and calls the cluster healthy while lag compounds inside it.

Each poll stays below the trip-wire, so a threshold-only monitor reads this cluster as green. By the time the absolute number breaches, the WAL receiver is saturated and writes are blocking.

Scenario B
Split-brain on the consensus fence

Patroni's quorum is engine-internal and can't arbitrate between two nodes that both believe they hold the lease.

A partition splits the cluster; a replica promotes itself while the old primary keeps serving writes. Both sides now believe they own the leader lease, and read-what-you-wrote is broken until the fence heals.

Scenario C
Failover succeeded at the WAL level but stale reads

Patroni promotes the replica with the freshest WAL and stops. Nothing checks that the read view is actually serving the latest writes.

The promotion is clean by every consensus metric, but the cached read view on the new leader is serving rows from before the failover. Application reads go stale silently.

The full comparison with Patroni lives on /compare/veritas-vs-patroni.

How Veritas detects them
Observe and diagnose across quorum, liveness, and WAL pressure
Scenario A

Observe. Veritas samples every poll and keeps the *slope* of the lag, not just the instantaneous value. A replica two seconds behind on three consecutive cycles is a different signal from one two seconds behind on a single isolated cycle, even when both readings trip the same absolute threshold.

Diagnose. The diagnose step correlates the lag slope with WAL pressure on the primary, replica liveness, and the recent commit rate. If the trend is compounding inside the threshold band, Veritas flags the cluster as drifting well before any individual reading crosses an absolute trip-wire.

Scenario B

Observe. The observe step reads quorum state, replica liveness, and lease ownership *across* the affected nodes in parallel — both sides of a partition report a healthy leader at the same instant, and that disagreement is itself the signal.

Diagnose. Diagnosis refuses any conclusion that cannot prove exactly one eligible leader. If two nodes claim the lease simultaneously, the loop labels the cluster ambiguous and refuses to act; the "true" answer is that there is no canonical leader to act on yet.

Scenario C

Observe. Consensus metrics look clean — the failover succeeded, replication has re-established, the alert has cleared. Veritas does not treat a successful promote as a closed incident; the observe step keeps watching read-view freshness on the new leader even after the consensus layer reports green.

Diagnose. The diagnose step checks the read view against the last-known-committed state and flags a recovery as incomplete unless an end-to-end read against the new leader returns the data the cluster most recently wrote. A heartbeat is not a probe.

How Veritas recovers
Act on a risk-scored plan — verify with a real probe
Scenario A

Act. The act step generates a remediation plan: pause the lowest-priority write classes long enough for the replica to drain, throttle the WAL receiver if the pressure is bidirectional, and keep the primary accepting critical-path traffic. The plan is risk-scored against the current commit rate and refused only if the throttle itself would breach a write-side SLO.

Verify. Verification replays a write–read probe from the application layer against the replica, not against the leader, and confirms read-your-writes holds across both nodes before closing the incident. A second probe runs five minutes later to catch drift that re-compounded after the throttle released.

Scenario B

Act. Recovery refuses to run. The risk-scored plan is generated but only accepted when the diagnose step can prove a single canonical leader; ambiguous quorum state is a hard refusal, not a degraded execution. The agent holds the same plan in memory and waits for the partition to resolve before acting.

Verify. Once the partition heals, exactly one promote is executed against the node the verify step proves is canonical, and the action is written to the tamper-evident ledger with the leader-ownership proof as evidence. The plan is single-shot; a second promote is never issued against any node that has not been re-proven canonical at the moment of action.

Scenario C

Act. The act step rolls the recovery back if the verify probe fails — promotion is reversed, the old leader is re-eligible, and the plan retries against a different replica with the freshest combined WAL + read-view consistency. Each retry is logged to the audit trail with the exact signal that failed the probe.

Verify. Verification is a real, end-to-end read against the new leader returning the data most recently committed cluster-wide, not a monitoring heartbeat. The incident only closes when that probe succeeds; the recovery is explicitly "incomplete" until the read view on the promoted node is proven current.

Run the recovery loop on your cluster

We’re taking design partners for the closed-loop recovery agent ahead of general availability. Tell us what’s running and we’ll schedule a 30-minute working session on your cluster.

Run the recovery loop on your cluster

Or write directly to veritas-2-2@polsia.app.