How to set a simple load balancing with DNS, even Google does it.
In this example we will setup load balancing for domain test.com with 3 web servers.
Here’s all what you will need:
– Multiple A records for host name or domain in the DNS service of your choice
– 3 VPS or Dedicated servers (even shared hosting account are fine)
Firstly to have a good load balancing you need to have a good, reliable and stable dns provider with multiple DNS servers.
With your Domain provider for domain in our example test.com we will set A record with the following IP’s.
– VPS1 IP: 18.104.22.168 (server location Germany)
– VPS2 IP: 22.214.171.124 (server location US)
– VPS3 IP: 126.96.36.199 (server location Japan)
Now you need to set A record for each of this IP addresses.
After you have done that test your DNS records, you should have them displayed similar to google’s.
Test and compare:
dig a google.com
Example output of google.com
;; ANSWER SECTION: google.com. 268 IN A 188.8.131.52 google.com. 268 IN A 184.108.40.206 google.com. 268 IN A 220.127.116.11 google.com. 268 IN A 18.104.22.168 google.com. 268 IN A 22.214.171.124 google.com. 268 IN A 126.96.36.199 google.com. 268 IN A 188.8.131.52 google.com. 268 IN A 184.108.40.206
Notice also that Google is using a 100-300 second TTL on its “A” records. This helps (but does not eliminate) client-side DNS caching that can lessen the effectiveness of the round-robin DNS load balancing.
For most purposes you don’t need to have a TTL that low, however. A TTL of 10 to 30 minutes is fine for most websites.
Each time you execute this command your first A record will be on the other server ip.
The order in which IP addresses are returned varies by the DNS server and provider used but often follows a round-robin or geographically specific algorithm.
The idea here is that different clients will get different ordered lists of IP addresses corresponding to your domain name. This has the effect of distributing requests across the group of IPs in a specific manner. If an IP address does not respond in an appropriate amount of time, the client will time out on that request and move on to the next IP address until the list is exhausted or it finds a connection that’s valid.
Now don’t forget that you need to have your website uploaded on all 3 servers.
For assistance you can contact our support