How to Create Load Balancers

Setting up a load balancer is a two step process: creating the load balancer and then adding backend Droplets.

Creating the Load Balancer

You can create a load balancer using the Create menu at any time or use the Create load balancer button on the Load Balancers overview page.

Create menu

On the creation page, you will:

  1. Choose a datacenter region. Your load balancer and Droplets need to be in the same datacenter, so choose the one where your Droplets are or will be located.

  2. Add forwarding rules. You need at least one rule to create a load balancer. You can either create new rules now by clicking the New Rule drop down, or accept the default route (HTTP port 80 on the load balancer to HTTP port 80 on the backend Droplets) and configure the rules you want after the load balancer has been created.

    The left side of each rule defines the listening port and protocol on the load balancer itself, and the right side defines where and how the requests will be routed to the backends. You can change the protocols using the drop down menus. If you use HTTPS or HTTP2, you will also be asked to choose an existing SSL certificate, create a free certificate using Let’s Encrypt, provide custom certificate files, or use SSL passthrough.

  3. Set advanced settings. Advanced settings allow you to modify some additional parameters for the load balancer. The defaults work well for most cases, but the options are:

    • Algorithm: The default round robin algorithm sends requests to each available backend in turn. The alternative least connections algorithm sends requests to the backend with the least number of active connections.

    • Sticky sessions: If your application’s sessions rely on connecting to the same backend for each request, you can enable sticky sessions. This sets a cookie with a configurable name and TTL (to define how long the cookie is valid) so that the load balancer can send future requests to the same server.

    • Health checks: The load balancer will only forward requests to Droplets that pass health checks. You can customize the criteria for the health checks or accept the default settings.

      In the Target section, you choose the Protocol (HTTP or TCP), Port (80 by default), and Path (/ by default) that Droplets should respond on.

      In the Additional Settings section, you choose:

      • The Check Interval, which is how many seconds the load balancer will wait between health checks.
      • The Response Timeout, which is how may seconds the load balancer will wait between responses.
      • The Unhealthy Threshold, which is how many consecutive times a Droplet must fail a health check before the load balancer stops forwarding traffic to it.
      • The Healthy Threshold, which is how many consecutive times a Droplet must pass a health check before the load balancer will forward traffic to it.
    • SSL: You can redirect HTTP requests on port 80 to HTTPS port 443 by enabling this option. Once you click Save, HTTP URLs will be forwarded to HTTPS with a 307 redirect.

    • Proxy Protocol: By default, client connection information (like IP addresses) only reach the load balancer. PROXY protocol passes this information along to the backend Droplets. Backend services need to accept PROXY protocol headers or the Droplets will fail the load balancer’s health checks.

  4. Choose a name and create. Load balancer names must be unique and contain alphanumeric characters, dashes, and periods only. Once created, you can change the name at any time by clicking on the existing name on the load balancer page.

Choosing Droplets

Your choice of Droplets will be limited to the region where the load balancer was created. You can add individual Droplets or select by using a tag. When you use a tag, only the tagged Droplets in the same region as the load balancer will be part of its pool. Only one tag can be used per load balancer.

Add Droplets by tag window

When you’ve selected the tag or the Droplets, click Add Droplets. The load balancer will check the health of the backend Droplets. Once the backends have passed the health check the required number of times, they will be marked healthy and the load balancer will begin forwarding requests to them.