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.

Warning: check your config.hosts

If you have set your config.hosts in Rails to only allow traffic from your own domain(s), your load balancer can be seen as a different host and be blocked by your application, which can bring down your entire application. You will need to add your load balancer's hostname to your allowed list, or disable the config.hosts feature (which we recommend against)

Add a load balancer

To add a load balancer to your application:

  1. Open the Application Overview from the Dashboard.
  2. Click Explore Add-ins or the green + in the Add-ins panel
  3. Click on Install Now under Load Balancer
  4. 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:

The time required to set up your load balancer will depend on which cloud provider you use. Once your load balancer is set up, it will be ready to distribute the load between your web servers. All your existing web servers will automatically be added to the load balancer.

When you have a load balancer on your application, your deployments can take place in serial to reduce downtime, or in parallel. Deploying in serial involves removing each server from the load balancer, deploying to it and then re-adding it to the load balancer in sequence.

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.

Please note

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:

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.