In part 1 of this series, we’d seen what a load balancer is, and how Digital Ocean has just introduced a new product that takes all the hard work of configuring out of the equation. In part 2, we’ll see how to actually set up the load balancer so that you can start sharing your traffic amongst a series of droplets in order to remove single points of failure and increase your capacity.
Setting up your Droplets
To set up your Digital Ocean load balancer, you need to make sure of the following:
Assets Duplicated on all the Droplets:
Sometimes however, you want a request to go to the same droplet each time – regardless of which one took the first request. These sort of “stateless” sessions can be configured while setting up the droplet using a feature known as “Sticky Sessions”.
Ensure that all your Droplets are in the Same Region:
Ideally, you would be able to have a load balancer that spreads the load amongst any droplets regardless of region. In fact, it might be preferable to have a request serviced by a datacenter that’s close to the origin request. However, this facility isn’t (yet) available in Digital Ocean load balancers. Right now, all the droplets need to be in the same region in order for the load balancer to cover them.
With these two pre-requisites, let’s see how to set them up.
Adding Tags to your Existing Droplets
A single load balancer might service several droplets. While they can be added manually, it’s much easier to group them together via tags. Adding and removing a tag from a droplet automatically removes it or adds it to the load balancer. You can add tags to droplets using the “Add tags” option in the droplet overview screen as shown here:
You can add several tags to a droplet. In this example, I add the “nyc” tag as shown here:
And I create a second droplet with another set of tags. But they both share “nyc”:
Creating Digital Ocean Load Balancers
Sign in to your Digital Ocean account, and navigate to the “Networking” link on the top of the page. Under that, go to the “Load Balancers” tab as shown here:
To start off you’ll have no load balancers, and you’ll see this message:
Click the button to start the load balancer creation process. You’ll be asked which droplets to add. Since I have two droplets using the “nyc” tag, I use that here:
Digital Ocean tells me that I have two droplets with the “nyc” tag in the “NYC3” region. From now onwards, whenever I create a new droplet and tag it with “nyc”, it will automatically add it to this particular load balancer.
The next step is to configure the forwarding settings. I’ve already explained the difference between passthrough and using a separate certificate in part 1 of the tutorial:
And finally when all the settings are complete, the load balancer is ready with its own IP address.
From now on, any requests sent to this IP address will be distributed amongst the various droplets. You can also configure the method used to circulate the requests like Round Robin etc.
All in all, the Digital Ocean load balancers remove much of the configuration and headache you would normally face when setting up such a complex system. There is still room for improvement, particularly when it comes to geolocation and allowing droplets to be selected from a number of regions. But it’s still an awesome way to remove single points of failure and add capacity and load distribution to your site.
Is your website slow?
Enter its URL below to find out now: