Cloudflare Docs
Load Balancing
Load Balancing
Edit this page on GitHub
Set theme to dark (⇧+D)

Load balancers

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, dev.example.com, etc.).


​​ Common configurations

For suggestions, refer to Common load balancer configurations.

​​ Load balancing and existing DNS records

For details about DNS records, refer to DNS records for load balancing.

​​ HTTP keep-alive (persistent HTTP connection)

Cloudflare maintains keep-alive connections to improve performance and reduce cost of recurring TCP connects in the request transaction as Cloudflare proxies customer traffic from its edge network to the site’s origin.

Ensure HTTP Keep-Alive connections are enabled on your origin. Cloudflare reuses open TCP connections for up to 15 minutes (900 seconds) after the last HTTP request. Origin web servers close TCP connections if too many are open. HTTP Keep-Alive helps avoid premature reset of connections for requests proxied by Cloudflare.

​​ Session cookies

When using HTTP cookies to track and bind user sessions to a specific server, configure Session Affinity to parse HTTP requests by cookie header. Doing so directs each request to the correct application server even when HTTP requests share the same TCP connection due to keep-alive.

For example, F5 BIG-IP load balancers set a session cookie at the beginning of a TCP connection (if none exists) and then ignore all cookies from subsequent HTTP requests on the same TCP connection. This tends to break session affinity because Cloudflare sends multiple HTTP sessions on the same TCP connection. Configuring the load balancer to parse HTTP requests by cookie headers avoids this issue.


​​ Create load balancers

For step-by-step guidance, refer to Create a load balancer.


​​ Properties

For an up-to-date list of load balancer properties, refer to Load balancer properties in the Cloudflare API documentation.


​​ API commands

The Cloudflare API supports the following commands for load balancers.

CommandMethodEndpoint
Create Load BalancerPOST/zones/:zone_id/load_balancers
Delete Load BalancerDELETE/zones/:zone_id/load_balancers/:id
List Load BalancersGET/zones/:zone_id/load_balancers
Load Balancer DetailsGET/zones/:zone_id/load_balancers/:id
Overwrite specific propertiesPATCH/zones/:zone_id/load_balancers/:id
Overwrite entire Load BalancerPUT/zones/:zone_id/load_balancers/:id