DNS load balancing and failover is a critical part of any web or application deployment. In this article, we will walk you through how to setup DNS load balancing and failover using AWS Route 53. First, let’s take a look at what DNS load balancing and failover is: DNS load balancing and failover is a process of distributing the traffic across multiple servers in order to ensure that all requests are handled equally. This can be done through a combination of round-robin, priority-based, or weighting algorithms. In most cases, DNS load balancer will also use failover mechanisms in order to keep your applications up and running even if one server goes down. Failover can be achieved through either AWS Route 53 or Amazon EBS instances. Route 53 is the more popular option because it offers many features such as automatic routing of requests based on IP addresses, multiple Availability Zone support, and more. EBS is also an option but it has some limitations such as lower performance when compared to Route 53. We will focus on Route 53 in this article because it offers many benefits for web and application deployments.
- First things first: In order to set up DNS load balancing and failover on your AWS account you’ll need to create an Amazon Route 53 instance:
- Next, create a new route53 zone:
- Add the following lines to your route53 zone file:
- Finally add the following two lines to your main routing table:
- Now you’re ready to start setting up DNS Balancing on your routes53 instance! To do so simply type the following command into your terminal:
- Once you’ve run this command you’ll see something like this in your console:
- You now have two routes53 instances set up with different balance settings configured! You can now start deploying applications by adding them both back into
Load Balancing is the concept of splitting application or network load between two or more servers, allowing for better performance and longer uptime. AWS’s Load Balancers cost money to run, but you can achieve the same effect for free using Route 53.
How Does DNS Load Balancing Work?
With a normal load balancer, like AWS’s Application Load Balancer, you direct all traffic towards the load balancer, and it handles the job of routing traffic to your instances. Really, all AWS’s load balancers are instances running a service like HAProxy, and handling a high amount of traffic.
RELATED: How to Set Up an HAProxy Load Balancer
The idea behind DNS load balancing is pretty simple. Even with the regular load balancer, the user needs to make a DNS lookup to know where to send any requests to your website. However, the DNS doesn’t have to be static, and that’s the idea that AWS’s Route 53 DNS service has implemented. Once set up, whenever User A requests the site, he will be sent to Server 1, and when User B requests the site, Route 53 will send them to Server 2 instead.
This can optionally be set up in a different pattern—failover. If your application can run on a single server, but you need 100% uptime, Route 53 can redirect traffic to a standby instance whenever the main instance becomes overloaded or unavailable.
If you want to set either of these patterns up, Route 53 makes it easy. If you’re not already using Route 53 and want to switch, you can read our guide on transferring your domain name to it.
RELATED: How to Transfer a Domain Name to AWS Route 53
Configuring Route 53
Sign in to the Route 53 management console, and select “Health Checks” in the sidebar, and create a new health check. These will be used to route traffic away from unhealthy instances in the scaling group. These cost $0.50 per month each to run, but they are optional.
Health checks have a few options, but mostly you’re just giving Route 53 an endpoint to monitor. You can use IP address or Domain name, but if you’re monitoring the health of an individual server, you’ll want to use the Elastic IP address for that server.
You’ll want to repeat this process for all of your servers, creating a health check for each.
Click on “Hosted Zones” in the sidebar, and bring up the hosted zone for your domain. “Create” or edit a new A Record, and enter in the IP address of one of your servers. You can also just use Aliases, which map dynamically to an AWS resource.
If you set the routing policy to “Weighted,” you can assign this record a weight. Giving a weight of 1 to multiple A Records will make Route 53 choose from between them equally. For “Set ID,” enter in something unique that’s the same for all records in this weighting group.
Below, click “Yes” for “Associate With Health Check,” and select the health check for this server. If the health check fails, this record won’t be picked.
Repeat this process for each server.
If you want to set up failover, instead set the routing policy to “Failover,” and select either “Primary” or “Secondary,” depending on the server. You’ll also want to link this with a health check.
Once you save the records, Route 53 should start balancing traffic.