Course/Chapter 10/5. Disaster Recovery & High Availability
    advanced
    Chapter 10: Scaling & Production Best Practices

    5. Disaster Recovery & High Availability

    Plan for failure with backups and redundancy.

    15m Lesson 5 of 5

    Mission-critical automations need a solid disaster recovery plan. Learn to design n8n deployments that survive hardware failures, data corruption, and outages.

    HA Architecture

    1. Database replication: PostgreSQL streaming replication
    2. Load balancing: Distribute webhook traffic across instances
    3. Automated backups: Daily database dumps + workflow exports
    4. Monitoring: Health checks with automatic restart
    5. Runbook: Documented recovery procedures

    Recovery Time Objectives

    • - RTO (Recovery Time Objective): How quickly must you be back online?
    • - RPO (Recovery Point Objective): How much data loss is acceptable?

    Disaster Recovery Checklist

    1. Database backups run daily and are stored off-site
    2. Backup restoration has been tested within the last 30 days
    3. Workflow exports are version-controlled in Git
    4. Credentials are documented (encrypted) separately
    5. A runbook exists with step-by-step recovery procedures
    6. At least one team member has practiced the recovery process

    Code Examples

    Health Check Endpoint Script
    bash
    #!/bin/bash
    # health-check.sh — Run every 5 minutes via cron
    
    N8N_URL="https://n8n.example.com"
    SLACK_WEBHOOK="https://hooks.slack.com/services/xxx"
    LOG_FILE="/var/log/n8n-health.log"
    
    # Check if n8n is responding
    STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$N8N_URL/healthz")
    
    if [ "$STATUS" != "200" ]; then
      # Alert the team
      curl -s -X POST "$SLACK_WEBHOOK" \
        -H "Content-Type: application/json" \
        -d "{\"text\": \"🚨 n8n is DOWN! Status: $STATUS\"}" 
      
      # Attempt auto-restart
      docker compose restart n8n
      echo "$(date) — n8n DOWN (status $STATUS), restarted" >> "$LOG_FILE"
    else
      echo "$(date) — n8n OK" >> "$LOG_FILE"
    fi

    Pro Tips

    • 💡Test your disaster recovery plan at least once a quarter — a plan you haven't tested is just a wish
    • 💡Store backups in a different region/provider than your n8n instance
    • 💡Keep your N8N_ENCRYPTION_KEY safe — without it, credential backups are useless

    Comprehension Quiz

    Answer 2 of 2 correctly to unlock lesson completion.

    1. What is RTO?

    2. How often should you test your disaster recovery plan?

    Pass the quiz above to unlock lesson completion