Using the Load balancer Add-in
A load balancer is used to distribute traffic across your web servers, and offers benefits such as maximizing throughoutput, minimizing response times and avoiding overload on any single server. Ultimately, load balancing increases the reliability of your application.
You can add either native load balancers (for cloud vendors) or an HAProxy load balancer for Registered Servers.
Add a load balancer
To add a load balancer to your application:
- Open the Application Overview from the Dashboard.
- Click Explore Add-ins or the green + in the Add-ins panel
- Click on Install Now under Load Balancer
- A panel will slide out from the left with options. Select what you need and then click Add Load Balancer to continue.
You can now watch the logs, as usual to see the progress of the process. Depending on which cloud provider you use, this load balancer will be set up differently:
- Amazon AWS: Elastic Load Balancing
- DigitalOcean: HAProxy
- Google Cloud Engine: Forwarding rules, target pools & health checks
- Linode: NodeBalancer
- Microsoft Azure: TrafficManager
- Rackspace: Rackspace Load Balancing
- CloudA: Load Balancing as a service
Automatic endpoint test
When a new load balancer is set up it will begin to ping your web endpoints to check their health. By default load balancers ping the root path of your application (
/) and if they receive a
200 response code, they will consider a server healthy.
If your application does not have a valid endpoint or route set for
/ then you can specify a custom path under the
httpchk option in your manifest file to ensure your application responds appropriately. We will configure the load balancer to ping that path rather than the root.
If your servers respond positively to the ping test, the load balancer will begin to distribute the load between them. If any of these ping tests fail, the load balancer will not distribute traffic to those servers that failed.
Adding multiple load balancers
One potential drawback of having a load balancer is that it is a single point of failure. To improve the high availability of an application, you can add more than one load balancer to it.
This feature is not currently supported by Digital Ocean (pending the release of DigitalOcean native load balancers) or for any other providers that have HAproxy as their only load balancer option.
To add a second load balancer to your application:
- First add a standard load balancer to your application. You can follow the instructions above to do so.
- Once this is in place, click the + on the Add-ins panel
- Click Install Now under Load Balancer
- Follow the rest of the flow to add your second load balancer
This new load balancer is essentially a clone of your first one. Whenever changes are applied to your first load balancer, they will also be applied to any clones. Both load balancers are “live” and can distribute traffic to your application, but actually switching between load balancers requires an update to your DNS (see below).
Switching between load balancers
To switch traffic between load balancers, you should update the public DNS record for your application to point at the CNAME of your target load balancer. You can find the CNAME for any load balancer by clicking on its name in the Add-ins panel at the bottom of the Application Overview.
We recommend keeping your TTL for these records set to 300 (5 minutes) to reduce any downtime to a minimum.