Seamless Failover at the Apex: How to Use Cloudflare Load Balancing for High Availability

Share this post on:

If you’re managing a production website, high availability isn’t a luxury — it’s a necessity. Imagine this: your primary server unexpectedly goes down. With no standby, your users are met with an error page and your brand takes a hit.

Now, imagine a better scenario — within seconds, traffic reroutes to a standby server, preserving uptime while you fix the issue. That’s the magic of Cloudflare Load Balancing. In this post, I’ll show you how to configure failover for your apex domain (e.g., example.com) using two backend servers: one live and one on standby.


The Goal

  • Primary server = serves live data.
  • Standby server = backup, possibly with older data.
  • Only use standby if primary fails.
  • Works even at the apex domain (thanks to Cloudflare Load Balancer).

Step-by-Step Configuration

1. Prep Your Infrastructure

Make sure both servers:

  • Are accessible via public IP or resolvable hostname.
  • Respond on a simple endpoint (like /health) that can be used for uptime checks.

2. Log In to Cloudflare

  • Go to the domain you want to configure.
  • Navigate to the “Traffic” section.
  • Open Load Balancing (note: it’s a paid add-on).

3. Set Up Your Load Balancer

Click “Create Load Balancer” and configure:

  • Hostname: Leave this blank for apex (example.com).
  • TTL: Use a low TTL (e.g., 30 seconds) for fast response to failures.

4. Create Pools

Pools define which servers serve traffic.

🔹 Pool 1: Primary

  • Name: Primary-Pool
  • Add your live server.
  • Configure a health check (e.g., https://yourdomain.com/health, status code 200).

🔹 Pool 2: Standby

  • Name: Standby-Pool
  • Add the backup server.
  • Use the same health check logic.

5. Define Failover Order

  • Drag Primary-Pool to the top.
  • Enable Failover mode.
  • Optionally disable session affinity (unless sticky sessions are needed).

6. Point DNS to Load Balancer

  • Go to the DNS tab for your domain.
  • Make sure your @ record is an A or CNAME pointing to the load balancer.
  • Keep orange cloud enabled for proxying and failover.

Testing the Setup

Bring your primary server offline or simulate a failed health check:

  • You should see traffic shift to the standby within seconds.
  • Restore the primary — traffic will return automatically once it’s healthy.

Pro Tip

Want a smarter health check than just HTTP 200? Write a custom /health route that tests:

  • Database connectivity
  • Disk space
  • App responsiveness
  • Anything critical to your service’s integrity

Share this post on:

Author: tayyebi

Tayyebi works in the role of Director at Gordarg where he is the founder. He is passionate about people, technology, and arts. Mohammad believes in communications, each of us has the power to empower their people with knowledge. He can be seen writing codes, playing music, biking, and reading.

View all posts by tayyebi >






www.Gordarg.com