Skip to content

Lesson 8 of 9 · 24m

Cloudflare Load Balancing and Failover

Pools, health checks, steering, session affinity, and the split-brain details that determine whether failover actually works.

A load balancer demo is always beautiful: two origins, one dies, traffic shifts, applause. Production failover is uglier. Health checks disagree with users, half-dead origins keep receiving traffic, and session affinity quietly pins people to the very failure you were trying to escape. Cloudflare Load Balancing is strong infrastructure — if you design the failure semantics instead of accepting defaults.

Model the service before configuring the product

A pool is a set of origins that can serve equivalent traffic. A monitor defines what "healthy" means. Steering decides how traffic is distributed among healthy pools. Those are three separate decisions and should be treated that way.

lb.example.com
  primary pool: iad-a, iad-b
  backup pool:  ams-a, ams-b
  monitor: HTTPS GET /healthz every 60s, expected 200

/healthz must test what users need, not what is cheapest. If the app returns 200 while its database is down, failover will not happen. If the health check performs a huge query, the monitor itself becomes load. A good check verifies critical dependencies shallowly and quickly.

Steering is a consistency decision

Round robin within a pool is easy. Across regions, steering has policy implications:

  • Proximity steering minimizes latency but can overload the nearest region.
  • Weighted pools help migrations and capacity differences.
  • Priority/backup pools are simpler to reason about for disaster recovery.
  • Geo steering can satisfy data-residency requirements, but it is not a compliance system by itself.

The important question is not "which algorithm?" but "what do users experience when capacity is partial?" Sometimes the correct failover is degraded global service rather than perfectly fast service for a lucky region.

Session affinity deserves suspicion

Cloudflare session affinity can pin clients to an origin using cookies. This helps stateful legacy applications, but it also weakens failover and spreads load unevenly. Prefer stateless application design. If affinity is unavoidable, understand exactly what happens when the pinned origin drains: new cookie, broken session, or forced reauthentication.

DNS failover is not magic either

Load balancing still rides on DNS answers and health detection intervals. Short TTLs help, but caching resolvers and client behavior mean failover is fast, not instantaneous. Design for retryable requests and idempotent operations; the edge cannot make a non-idempotent POST safe after the client times out.

Field notes

  • Test failover by removing capacity safely, not by reading the dashboard. Game days expose monitor blind spots.
  • Alert on pool health transitions and origin latency separately. A backup pool serving everyone is technically healthy and operationally urgent.
  • Keep backup capacity real. A failover target at 5% normal capacity is a decorative asset.
  • Authenticated origin pulls or mTLS matter here too; otherwise attackers can hit origins directly and bypass the load balancer's controls.

Was this lesson helpful?

Sign in to rate