How to Implement Cheap DNS Load Balancing and Failover Using AWS Route 53

networking speed

Load balancing is the concept of distributing the application or network load between two or more servers, resulting in better performance and longer uptime. AWS load balancers cost money to run, but you can get the same effect for free using Route 53.

How does DNS load balancing work?

With a normal load balancer, like that of AWS Application Load Balancer, you direct all traffic to the load balancer, and it manages the routing of traffic to your instances. In reality, all AWS load balancers are instances running a service such as HAProxyand handle high traffic.

The idea behind DNS load balancing is quite simple. Even with the standard load balancer, the user must perform a DNS lookup to find out where to send requests to your website. However, DNS does not need to be static, and this is the idea that the AWS Route 53 DNS service has implemented. Once configured, every time User A requests the site it will be sent to Server 1, and when User B requests the Site, Route 53 sends them to Server 2 instead.

User A requests site, is sent to server 1. User B requests site, Route 53 sends to server 2 i

This can optionally be configured according to a different model: 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 primary instance is overloaded or unavailable.

If you want to configure one of these templates, Route 53 makes it easy for you. If you are not already using Route 53 and want to change, you can read our guide to transferring your domain name.

Configure Route 53

Connect to Route 53 management consoleand select “Health Checks” from the sidebar and create a new health check. These will be used to route traffic away from bad instances in the sizing group. These cost $ 0.50 per month each, but they are optional.

Health checks have a few options, but most of the time you just give Route 53 an endpoint to watch out for. You can use the IP address or the domain name, but if you are monitoring the health of an individual server, you will want to use the Elastic IP address for that server.

Configure health check

You will want to repeat this process for all of your servers, creating a health check for each.

Click on “Hosted Zones” in the sidebar and display the hosted zone for your domain. “Create” or modify a new A record and enter the IP address of one of your servers. You can also just use aliases, which dynamically map to an AWS resource.

If you set the routing policy to “Weighted”, you can assign a weight to this record. If you give a weight of 1 to multiple A records, Route 53 will choose between them equally. For “Set ID”, enter something unique that is the same for all records in that weight group.

Below, click “Yes” for “Associate with health check” and select the health check for this server. If the health check fails, this record will not be selected.

Repeat this process for each server.

If you want to configure failover, instead set the routing policy to “Failover” and select “Primary” or “Secondary”, depending on the server. You’ll also want to associate this with a health check.

Configure failover.

After you’ve saved the records, Route 53 should start balancing the traffic.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.