Load balancing is one of the primary techniques used to scale websites and apps that get a lot of traffic or have a large number of users. In essence, it’s simply sharing the load among multiple machines, which may also include a certain degree of fail-over protection (if one server goes down, the others take over the job). [7 Best CDN Options For Your Website]
Load balancing makes sense not only for large scale apps, but also for normal websites that need to have high availability and be able to go through traffic spikes without being knocked out of service.
Most of the times, webmasters just choose to go with higher end hardware for their server, but load balancing between two or more machines can provide a huge benefit in terms of bandwidth – having two small servers that have their own 1 Gbps connection is a lot better (and cheaper, even with the load balancing front server) than having one powerful machine on a single 1 Gbps connection, for example.
Large load balancing setups can get really complicated, but let’s take a look at the most common and practical ways to do it for the average website/app that is experiencing noticeable growth and could use a boost in speed and reliability.
Probably the simplest and cheapest method of load balancing, round robin DNS involves using the DNS system to your advantage, and setting it up to point to multiple IPs/machines that have an identical set up (i.e. both serve the same content/application).
Since DNS records can point to several IP addresses, you can set up a DNS server and a reverse proxy that would point to several different machines – IPs are served in a rotated manner, so client 1 will receive IP 1, client 2 will receive IP 2, and so on. There will be some differences based on geography, because nodes are configured to access the closest server, but that can actually work to your advantage if you’re load balancing for worldwide clients and have servers on different continents/countries.
This setup allows you to quickly and easily balance load distribution across multiple servers, and it may even provide a small degree of failover – if one server goes down, clients will still be able to access the other machines. You should not count on that, however – since ISPs and client machines cache DNS records (even if you set TTL to 0), if the server that they first accessed (or frequently access) goes down, they will simply not be able to access it at all.
Still, if you keep your servers in working order and monitor them frequently, round robin DNS is a very fast way to scale up anything without too much expense.
If you need a truly reliable load balancing set up, using dedicated hardware is the only way to go. Thankfully, you don’t need to pay for expensive specialized hardware – with the appropriate software, any dedicated machine can do the job. Furthermore, cloud servers and VPS are a great choice since they can have access to a large bandwidth pool, and are infinitely scalable themselves.
Amazon, Linode, Rackspace and many other companies offer load balancing solutions that are ready to go out of the box, but if you want, you can set everything up yourself from scratch. It’s usually cheaper to use one of the many load balancing services that these companies offer when you’re starting out, but as you grow bigger, a custom solution can be much cheaper, more efficient and better suited for your purposes.
Last but not the least, I thought I would mention an obvious, but often overlooked solution for beginners who use a single machine for everything (hosting static files for downloads, databases, email, DNS, etc.) – split your applications to different servers!
It is the standard practice for pretty much every company that needs to grow, but for some reason, many people choose to use a single server for everything. Sure, it’s convenient, but it’s the most unreliable thing you can do.
Having several servers for each of your main applications can make your whole set up faster, more reliable and more robust. You can use different servers – small and cheap ones for DNS, large storage and bandwidth for downloads, lots of CPU cores and RAM for the application server, SSDs for the static files and database server, and more – it’s a very flexible option.
And you can use load balancing afterwards, as well! Setting everything up may not be as easy, but it’s the best way to go, as proven time and time again by startups and system administrators all over the world.
Load balancing is a great solution to scaling websites and applications – depending on your needs, you can set it up for high availability or simple load balancing. It’s a better option than more powerful hardware, although a combination of the two would be perfect.
I’d recommend starting out with better caching software, then moving on to dedicated machines for the databases, DNS and application servers, and only then move to true horizontal scaling by load balancing with round robin DNS or dedicated front machines. Good luck in your endeavors!