Auto-Healing and self-recovery systems
1) What is auto-healing and why is it needed
Auto-healing is an automatic stabilization of the service in case of failures without human intervention, with symptom recovery priority (SLO) over root cause search (RCA).
Goals: Lower MTTR, protect flawed budgets, reduce operating costs and human error.
- Detection (metrics/logs/synthetics/events).
- Solution (rules/policies/ML heuristics).
- Action (restart/scale/shedding/ficheflag/rollback/feilover).
- Verification (SLO green in the given window).
- Revert on degradation.
2) Auto-healing mechanism map
At the application level: idempotency, timeouts, retry + backoff + jitter, circuit breaker, bulkhead, cache degradation (graceful).
Kubernetes: liveness/readiness/startup probes, restartPolicy, PDB, HPA/VPA, Descheduler, Pod/Node auto-remediation.
Network/edge: rate limits, per-tenant quotas, connection draining, fail-open/close, WAF rules.
Queues/streaming: consumer-autoscale, lag-based backpressure, DLQ/parking lot.
Storage/DB: replica-feilover, auto-repair (rebuild), throttled autovacuum, connection pool rebalancing.
CI/CD: canary calculations, progressive delivery, auto-rollback.
Event orchestration: controllers/operators, workflow engines (Argo, Airflow) with retry policies.
Watchdog/Heartbeats: Dead Man's Switch for background jobs.
3) Safe self-recovery design principles
1. SLO-driven: all automatic actions are triggered by symptoms tied to user experience.
2. Canary-first: first locally/pointwise, then globally.
3. One-way door guardrails: rollback by timer/condition, "double key" for risky operations.
4. Idempotency: each action (restart, migration, rotation) is safe to repeat.
5. Observability-by-design: action labels, correlation with traces, who/what/when/why log.
6. Least privilege: automation has minimal rights (RBAC, scoped secrets).
7. Cost-aware: limits on "expensive" actions (scaling, egress, snapshots).
4) Detection: signals to start auto-healing
Метрики: 5xx%, p95/p99 latency, Kafka lag, DB lock/lag, node pressure.
Synthetics: uptime fall/path regression (login/deposit).
Logs: new error signatures, exception rate.
События K8s: CrashLoopBackOff, NodeNotReady, FailedScheduling.
Heartbeat: Silence of the job> N minutes.
promql
API error regression sum (rate (http_requests_total{status=~"5"..}[5m]) )/sum (rate (http_requests_total[5m]))> 0. 01
Kafka: lag> threshold max by (topic, group) (kafka_consumergroup_lag)> 10000
K8s: pod в CrashLoopBackOff increase(kube_pod_container_status_restarts_total[5m]) > 3
5) Auto-restore actions (playbook)
5. 1 Application/network
Circuit breaker ON with backend anomaly → fast fail-fast + cache/stab responses.
Retry + backoff + jitter with limits and de-duplication.
Rate limit/shed-load: under overload - prioritization of critical paths.
5. 2 Kubernetes
Restart the container (liveness) and remove the hearth on a non-healthy node.
HPA/VPA: auto-scale by RPS/CPU/latency/lag; VPA - only recommendations or off-hours apply.
Auto-remediation of nodes: cordon + drain for persistent problems (tains).
Affinity/Topology spread for protection against AZ-files.
5. 3 Queues/Streaming
Auto-scale consumers по lag; temporary reduction of throughput producers.
DLQ for poisonous messages; replay from archives.
5. 4 DB/Cache
Failover to replica with state/configuration validation.
Connection pool reset for connection leaks.
Hot-standby promote with automatic reconfigure of clients.
5. 5 CI/CD
Auto-rollback with 5xx/p95 growth on canary traffic.
Feature-flags: automatic OFF of problematic feature instead of global rollback.
6) Progressive delivery and auto-rollback
Example (Argo Rollouts Canary Strategy)
yaml strategy:
canary:
canaryService: api-canary stableService: api-stable steps:
- setWeight: 10
- pause: {duration: 5m}
- analysis:
templates:
- templateName: api-slo-check
- setWeight: 25
- pause: {duration: 10m}
- analysis:
templates:
- templateName: api-slo-check
If the template analysis returns "fail" (errors/latency exceeded), rollout is automatically rolled back.
7) Feature flags as a self-recovery tool
Kill-switch for problematic features (server-side).
Targeting: disable feature on segment/region.
Auto-rule: if 5xx% of the feature> X in Y minutes is OFF and the ticket is in backlog.
Verification: SLO-panel feature with budgets.
8) Overload: how not to "treat" yourself to death
Shed-load: reject/lower the QoS of non-critical requests (tariffs, heavy-reports).
Token-bucket/leaky-bucket and tenant/key quotas.
Adaptive concurrency (at the proxy/SDK level) - reduce concurrency when latency increases.
Bulkhead: isolating thread/connection pools.
9) Consistency and idempotency
Idempotent keys (request_id) → protection against repetition.
Fearful transactions (payments, write-offs) - two-phase processes, confirmation/compensation (saga).
Outbox/Inbox и exactly-once через idempotency storage.
10) Safety and compliance
Minimum RBAC for automatics (only the necessary resources).
Audit of all actions: who/when/what signal/what effect.
Manual override and "red button" to disable auto-actions.
Legal Hold on incident artifacts and automation logs.
Secrets - through a secret manager, key rotation during self-actions.
11) FinOps: the price of "self-healing"
Limits on the maximum autoscale so as not to go broke with a splash.
Cost per action metrics: cost of 1 restart, 1 additional replica, 1TB egress.
Aggregates: cost per SLO-minute saved, cost per mitigated incident.
"Night mode" policies: the aggressiveness of the automation is lower if business traffic is low.
12) Observability of automation
Labels on the graphs:' remediation _ action =" rollback"',' source =" argo"', 'reason = "slo _ burn"'.
Separate dashboard: frequency of auto-actions, success, median recovery time, rollback rate.
Effect → SLO correlation for benefit assessment.
13) Configs and examples
13. 1 K8s: probes and restart policies
yaml livenessProbe:
httpGet: { path: /healthz, port: 8080 }
initialDelaySeconds: 20 periodSeconds: 10 timeoutSeconds: 2 readinessProbe:
httpGet: { path: /readyz, port: 8080 }
periodSeconds: 5 failureThreshold: 3 startupProbe:
httpGet: { path: /startupz, port: 8080 }
failureThreshold: 30 periodSeconds: 5
13. 2 Alert → auto-action (pseudo)
yaml rule: api_5xx_rate_high action:
type: feature_flag target: "payments. new_flow"
set: false guardrails:
cooldown: 10m max_actions_per_hour: 2 rollback_if:
- condition: "5xx% not reduced within 5m"
13. 3 Kafka lag autoscale (HPA by custom metric)
yaml metrics:
- type: Pods pods:
metric:
name: kafka_consumer_lag target:
type: AverageValue averageValue: "500"
14) Testing auto-healing (chaos & game days)
Chaos injections: network pauses, killing pods/nodes, database/cache degradation.
Game days: scenario training with time limit and MTTR metrics.
Shadow traffic: rental of traffic to the canary without affecting users.
Dry-run automation modes (we write, but do not do).
15) Criteria for "auto-recovery readiness"
- SLOs are defined, metrics are stable, there are synthetics.
- Samples/healthz ,/readyz ,/startupz correctly reflect the condition.
- Identity and double protection (especially in payments).
- Feature flags and canary displays are available.
- Guardrails: cooldown, rate-limit actions, double key for high-risk operations.
- Automation dashboard and audit logs.
- Manual override and runbooks plan in case of jamming.
16) Implementation by phase (4 iterations)
1. Base: define SLO, add probes, include restarts/main alerts.
2. Local actions: phicheflag-kill-switch, lag-scaling consumers, auto-rollback canaries.
3. Infra-level: node remediation, database/cache failover, load shading.
4. Optimization: guardrails, FinOps limits, chaos tests, ML heuristics for detection.
17) Frequent errors and anti-patterns
Treating the cause to symptoms → long MTTR.
Global actions without canary stage.
No rollback or no undo criteria.
False health checks (200 for broken addiction).
"Bloat" autoscale without limits/cost thresholds.
Blind retray storm without backoff and deduplication.
18) Mini-FAQ
Do you need ML for auto-scoring?
No, it isn't. Start with rules on SLO/metrics and guardrails; ML is useful for anomalies and predicates.
Why doesn't restarting always help?
If the root is dependent (database, cache, network), the restart will only aggravate the storm. Need a breaker/shedding/feilover.
How to prove the benefits?
Compare MTTR and consumption of erroneous before/after budget. Add cost per mitigation metrics.
Total
Auto-healing is a system, not a set of "restart crutches": SLO-detection → safe point actions → verification → rollback when worsened. By combining probes, canary calculations, feature flags, scaling, shading, faylovers and strict guardrails, you reduce MTTR, keep the budget erroneous and keep the cost under control.