Skip to content
Load Balancing
Visit Load Balancing on GitHub
Set theme to dark (⇧+D)

Create a load balancer

A load balancer distributes traffic among origin pools according to pool health and its steering policy. Each load balancer is identified by its DNS hostname (lb.example.com, www.example.com, etc.).

For more details about load balancers, refer to Load balancers.

Via the dashboard

  1. Go to Traffic > Load Balancing.

  2. Click Create Load Balancer.

  3. On the Hostname page:

    • Enter a Hostname, which is the DNS name at which the load balancer is available. For more details on record priority, refer to DNS records for load balancing.
    • Toggle the orange cloud icon to update the proxy mode, which affects how traffic is routed and which IP addresses are advertised.
    • If you want session-based load balancing, toggle the Session Affinity switch.
  4. Click Next.

  5. On the Add an Origin Pool page:

  6. Click Next.

  7. On the Monitors page:

    • Review the monitors attached to your pools.
    • If needed, you can attach an existing monitor or create a new monitor.
  8. Click Next.

  9. On the Traffic Steering page, choose an option for Traffic steering.

  10. Click Next.

  11. On the Custom Rules page, select an existing rule or create a new rule.

  12. Click Next.

  13. On the Review page:

    • Review your configuration and make any changes.
    • Choose whether to Save as Draft or Save and Deploy.

Via the API

For a full list of properties, refer to Create Load Balancer. If you need help with API authentication, refer to Cloudflare API Quickstart.

Request
curl -X POST \
-H "X-Auth-Email: user@cloudflare.com" \
-H "X-Auth-Key: REDACTED" \
"https://api.cloudflare.com/client/v4/zones/:zone_id/load-balancers" \
-H "Content-Type: application/json" \
-d '{
"description": "Load Balancer for lb.example.com",
"name": "lb.example.com",
"enabled": true,
"ttl": 30,
"fallback_pool": "17b5962d775c646f3f9725cbc7a53df4",
"default_pools": [
"17b5962d775c646f3f9725cbc7a53df4",
"9290f38c5d07c2e2f4df57b1f61d4196",
"00920f38ce07c2e2f4df50b1f61d4194"
],
"proxied": true,
"steering_policy": "dynamic_latency",
"session_affinity": "cookie",
"session_affinity_attributes": {
"samesite": "Auto",
"secure": "Auto",
"drain_duration": 100
},
"session_affinity_ttl": 5000,
}'

The response contains the complete definition of the new load balancer.

Response
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "699d98642c564d2e855e9661899b7252",
"created_on": "2021-01-01T05:20:00.12345Z",
"modified_on": "2021-01-01T05:20:00.12345Z",
"description": "Load Balancer for lb.example.com",
"name": "lb.example.com",
"enabled": true,
"ttl": 30,
"fallback_pool": "17b5962d775c646f3f9725cbc7a53df4",
"default_pools": [
"17b5962d775c646f3f9725cbc7a53df4",
"9290f38c5d07c2e2f4df57b1f61d4196",
"00920f38ce07c2e2f4df50b1f61d4194"
],
"proxied": true,
"steering_policy": "dynamic_latency",
"session_affinity": "cookie",
"session_affinity_attributes": {
"samesite": "Auto",
"secure": "Auto",
"drain_duration": 100
},
"session_affinity_ttl": 5000,
}
}

Sharing your load balancer with other sites

You can share your load balancer with other sites in your account by creating a canonical name (CNAME) record. This is useful for sharing configurations with multiple other domains so you do not have to create new load balancers for each site.

You can also configure separate load balancers for each domain and reuse monitors and pools. This is especially useful for changing the failover order for different domains, such as when your example.co.uk server has a different failover priority from example.com or example.com.au.