Skip to content

Cloudflare Load Balancing — Failover & Health Checks Explained

DodaTech Updated 2026-06-23 4 min read

In this tutorial, you'll learn about Cloudflare Load Balancing. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

Cloudflare Load Balancing failover automatically redirects traffic away from unhealthy origins and pools, keeping your application online when servers fail. This tutorial explains how health checks trigger failover events, how to configure notification alerts, and how to override failover behavior manually.

Why Failover Matters

Every minute of downtime costs revenue, reputation, and user trust. A load balancer with failover detects when a server stops responding and reroutes traffic to healthy alternatives in seconds. Cloudflare performs this at the edge, so failed origins never see traffic until they recover.

Real-world use: Durga Antivirus Pro uses Cloudflare failover across three pools (US, EU, APAC). When the EU pool experienced a datacenter power outage, traffic automatically shifted to the US and APAC pools with zero manual intervention and 47 seconds of detection time.

Failover Flow

flowchart TD
  REQ[Incoming Request] --> LB[Load Balancer]
  LB --> P1[Primary Pool]
  P1 --> M1[Monitor: Healthy]
  M1 -->|Pass| O1[Origin responds]
  M1 -->|Fail| P2[Secondary Pool]
  P2 --> M2[Monitor: Healthy]
  M2 -->|Pass| O2[Origin responds]
  M2 -->|Fail| P3[Tertiary Pool]
  P3 --> M3[Monitor: Healthy]
  M3 -->|Pass| O3[Origin responds]
  M3 -->|Fail| DRO["Drop Request / 503"]
  style P1 fill:#090,color:#fff
  style P2 fill:#f90,color:#fff
  style P3 fill:#f90,color:#fff
  style M1 fill:#090,color:#fff
  style M2 fill:#090,color:#fff
  style M3 fill:#090,color:#fff
  style DRO fill:#c00,color:#fff

Configuring Health Monitors

A health monitor defines how Cloudflare checks origin availability. Every pool must have at least one monitor attached for failover to work.

# Create an HTTP health monitor
curl -X POST https://api.cloudflare.com/client/v4/accounts/{account_id}/load_balancers/monitors \
  -H "Authorization: Bearer {api_token}" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "http",
    "description": "Production health monitor",
    "method": "GET",
    "path": "/healthz",
    "interval": 30,
    "retries": 3,
    "timeout": 10,
    "expected_codes": "2xx",
    "follow_redirects": true,
    "allow_incomplete": false
  }'

# A 30-second interval with 3 retries means an origin can be
# marked unhealthy in as little as 90 seconds
# Create a TCP health monitor for non-HTTP services
curl -X POST https://api.cloudflare.com/client/v4/accounts/{account_id}/load_balancers/monitors \
  -H "Authorization: Bearer {api_token}" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "tcp",
    "description": "TCP port health check",
    "method": "TCP_HANDSHAKE",
    "port": 3306,
    "interval": 30,
    "retries": 2,
    "timeout": 10
  }'

# Useful for database ports, custom protocols, or SSH services

Pool Failover Ordering

Pools are ordered by priority. The load balancer routes traffic to the highest-priority pool. When that pool becomes unhealthy, traffic cascades to the next priority level.

# Pool priority ordering
# Pool 1 (priority 0): us-east - primary
# Pool 2 (priority 1): eu-west - secondary
# Pool 3 (priority 2): apac - tertiary
# All origins in Pool 1 must be unhealthy before Pool 2 receives traffic
# Configure pool priorities via API
curl -X PUT https://api.cloudflare.com/client/v4/accounts/{account_id}/load_balancers/{lb_id} \
  -H "Authorization: Bearer {api_token}" \
  -H "Content-Type: application/json" \
  -d '{
    "pools": [
      {"id": "pool-us-east", "weight": 1},
      {"id": "pool-eu-west", "weight": 1},
      {"id": "pool-apac", "weight": 1}
    ],
    "steering_policy": "standard",
    "description": "Failover-ordered load balancer"
  }'

# Pools are evaluated in array order for failover cascade

Notification Alerts

Cloudflare can send alerts when pools or origins change health status. Configure these under Notifications in the dashboard.

# Create a load balancing alert via API
curl -X POST https://api.cloudflare.com/client/v4/accounts/{account_id}/alerting/v3/policies \
  -H "Authorization: Bearer {api_token}" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Pool Health Alert",
    "alert_type": "load_balancing_pool_health",
    "enabled": true,
    "mechanisms": {
      "email": [{"id": "ops-team"@example".com"}],
      "webhooks": [{"id": "slack-webhook-id"}]
    }
  }'

# Alerts fire when pool health changes from healthy to unhealthy or vice versa

Manual Override

Sometimes you need to take a pool out of rotation for maintenance without triggering automatic failover.

# Disable a pool manually via API
curl -X PATCH https://api.cloudflare.com/client/v4/accounts/{account_id}/load_balancers/pools/{pool_id} \
  -H "Authorization: Bearer {api_token}" \
  -H "Content-Type: application/json" \
  -d '{"enabled": false}'

# Traffic immediately bypasses the disabled pool.
# Re-enable with {"enabled": true} when maintenance is complete.

FAQ

How fast does Cloudflare failover happen?

Failover occurs as soon as the health monitor detects a failure. With a 30-second interval and 2 retries, detection takes 60 to 90 seconds. You can reduce this by lowering the interval and retry count.

What happens when a failed origin recovers?

The health monitor sends the next scheduled check. If the origin responds with the expected status code, Cloudflare marks it healthy and it starts receiving traffic again according to the pool priority order.

Can failover cause a thundering herd problem?

Cloudflare mitigates this with gradual re-enablement. When an origin recovers, traffic is ramped up over a short period rather than all at once, preventing sudden load spikes from overwhelming the restored server.

Practice Questions

  1. How does pool priority ordering affect failover behavior?
  2. What configuration parameters influence how quickly Cloudflare detects an unhealthy origin?
  3. How would you gracefully remove a pool for maintenance without causing errors?

Summary

Cloudflare Load Balancing failover relies on health monitors that check origins at configurable intervals. When monitors detect failures, traffic cascades to the next healthy pool in priority order. Notifications alert teams when pool health changes, and manual overrides allow graceful maintenance. Properly configured failover provides automatic resilience against server outages.

Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro — security-first tools for the modern web.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro