…Even Google does it. I’m talking about load balancing via DNS. If you find yourself in a situation where one server isn’t cutting it anymore and you would like to easily distribute load across several servers with identical configuration answering to the same backend, one way to accomplish it is to use round-robin DNS. It’s even easier than it sounds…
The first step is to set up your servers with individual public IPs. (That was easy). Now make an “A” record for each one in your DNS configuration. The result is that your DNS server, such as bind, will rotate the IP addresses handed out to remote clients. This is the default behavior for most DNS servers; if it isn’t the default for yours, customize config as necessary– this writeup is not going to go into detail about such configuration. If you need to, Goog it.
What it ends up looking like is something akin to what you see in the screenshot below (in this example, I’m using Google’s servers). Notice that one request for the “A” record for google.com yields several different results for my web client to choose from. Notice again that another request only a couple seconds later yields even more choices, different from the first. Google is making sure that requests for their servers get spread out across many different inroads, and while I’m sure they have some great hardware-based load balancing in their datacenters, they’re still using this technique too:
Notice also that Google is using a 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 a TTL that low, you’ll need some beefy name servers, and DNS service that lets you set a TTL that low. I think that for most purposes you don’t need to have a TTL that low, however. A TTL of 15 to 30 minutes is fine for most websites.
Bear in mind that due to the nature of very common client-side DNS query caching, your round-robin DNS load balancing is not likely to distribute the load on your remote servers on a per-request basis. It will be more like a per-session basis. Nothing is truly guaranteed, however, without real hardware-based load balancing.
Think of this as a “poor man’s” load balancing solution. You’ll get some mileage out of it, but it’s not a substitute for say, a BigIP f5 load balancer cluster 😉
For even more effective (and low-cost/free) load balancing solutions, look at technology like the HA Linux project: http://www.linux-ha.org