Load balancing with DNS records
To randomly distribute traffic across multiple servers, set up multiple DNS
AAAA records for the same hostname.
The following example illustrates how you would distribute traffic intended for
www.example.com. Though the example uses
A records, you could also use
All records unproxied
If all associated records were unproxied, any request to Cloudflare’s nameservers would return the three
A records you previously added.
Each client (oftentimes a browser), would decide which IP address to send the request to. If one IP address fails, the client would choose another option. All requests would be sent directly to the origin server (to
All records proxied (recommended)
If all associated records were proxied, any request to Cloudflare’s nameservers would return two
A records from Cloudflare’s list of edge IP addresses.
Each client (oftentimes a browser) would decide which Cloudflare IP address to send the request to. Cloudflare would then receive that request and — if Cloudflare needed to contact your origin server — we would pick one of the three IP addresses specified in your DNS records (
Beyond reducing requests to your origin server, this setup allows your application to take advantage of Cloudflare’s Zero downtime failover. When a request to one IP address fails, Cloudflare automatically retries the request to other IP addresses associated with the same hostname. This behavior prevents end users from experiencing downtime.
Unproxied and proxied records
This approach is not typically recommended because it can lead to unexpected behavior. For example, if you had two unproxied records and one proxied record, Cloudflare would treat all records as proxied. However, if you deleted the single proxied record, your remaining two unproxied records would immediately be treated as unproxied.
We recommend either using all proxied or all unproxied records to avoid surprises when you make changes to your DNS records.