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.

DigitalOcean Load Balancers select name

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.

  1. 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 healthy servers. You can modify the criteria the Load Balancer uses to remove and re-add server as well as the endpoint it checks for a response.
    • SSL Redirect: 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.
  2. 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.

DigitalOcean Load Balancers add by tag

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.