Stackbook Logo
resilienceestablished · low operational burden

Self-Healing Watchdog

Also known as: watchdog-timer, auto-remediation, supervisor-restart

Intent

Automatically detect stuck or failed components and restart or replace them without human intervention.

Problem

Processes crash, deadlock, or leak resources, and waiting for a person to notice and restart them extends outages and burns on-call time. Many faults are transient and fixed by a clean restart.

Forces

  • •Fast recovery vs risk of restart loops
  • •Detection must not itself be a single point of failure
  • •Restarting can destroy diagnostic evidence
  • •Not every fault is fixed by restart

Solution

Overview

A watchdog turns operational knowledge into automation: if a component stops making progress, restart it. The approach comes from hardware watchdog timers and is the core of Erlang supervisors and Kubernetes restart policies.

How it works

The monitored component must regularly prove progress, and the supervisor acts when it does not.

loop:
  do work
  watchdog.kick()          # resets countdown

supervisor:
  if no kick for 30s:
      dump threads and heap
      restart component
      backoff = min(backoff * 2, 5m)
      if restarts > 5 in 10m: quarantine and page

Kick the watchdog from the place that proves useful work, such as after processing a message, not from an independent timer thread.

Pitfalls

  • A background thread that kicks on a timer reports health even if the worker is deadlocked.
  • Restart loops hide root causes and can overload dependencies on startup. Use backoff and a ceiling, then escalate.
  • Collect a core dump or thread dump before restarting so the bug can still be diagnosed.
  • A fleet-wide shared fault can trigger every instance to restart simultaneously. Limit concurrent restarts.
  • Restarting a stateful process requires safe recovery from its journal or snapshot.

Key takeaways

  • Tie the watchdog to real progress.
  • Capture evidence before restarting.
  • Use backoff, limits, and escalation to prevent loops.
  • Treat automatic restarts as a metric to investigate, not a fix.
  • Alert on restart counts per component, because a rising restart rate is an early warning of a leak or defect even when users notice nothing.

✓ When to Use

  • •Long-running daemons and workers
  • •Containerized services under an orchestrator
  • •Embedded and edge devices without operators nearby

✗ When Not to Use

  • •Faults caused by bad data or configuration that a restart cannot fix
  • •Stateful processes where restart risks corruption without recovery logic
  • •When restarts hide a leak that should be fixed

Pros

  • +Shortens recovery time dramatically
  • +Reduces on-call burden
  • +Handles transient faults automatically

Cons

  • −Can mask underlying bugs
  • −Restart loops can worsen outages
  • −Needs good progress signals

Cost Profile

Infrastructure

Low, supervisor tooling is common

Operational

Medium, tune thresholds and escalation

Cognitive

Low to medium

Failure Modes

  • Crash loop repeatedly restarts a poisoned component and hammers dependencies

  • Watchdog thread keeps kicking while main work is stuck

  • Mass restart triggered by shared dependency outage causes a thundering herd

Real-World Examples

Alternatives

    Related Patterns

    • health-check-endpoint
    • heartbeat

    Competency Domains

    reliability ops