Last week we looked at Dockerizing a Go application and exposing it to the world via NS1 DNS. This week we’re going to look at one specific option of load balancing: DNS load-balancing.
DNS Load Balancing
DNS load balancing is traditionally a basic but fast type of load balancing that utilizes round-robin routing. Historically, there were reliability issues with this method due to DNS not checking for server or network outages or errors, resulting in downed and inaccessible servers being served. At the end of this post we’ll cover a way around this issue leveraging NS1’s Filter Chains.
When we set up our last server, we spun it up in NY. To implement round-robin routing, let’s first create a snapshot of our current server and deploy it in San Francisco.
Using the snapshot we just created as an image, let’s spin up a new server in San Francisco. This will provide a better experience to our users on the West Coast.
Let’s SSH into our new server and run our container:
$ docker run --name web-app --rm -p 80:80 web-app
And now let’s navigate to our browser and go to the IP address of our new server:
Now we have two instances of our application, but only one is resolving under our domain. To fix that, let’s head over to our NS1 Developer Account that we set up last week and simply click our A name record in our zone:
On this new page, click “Add Answer” and type the IP address of your new server and click “Save Record.”
Now let’s perform a DNS lookup for the domain to verify the answers for the request:
$ dig A @dns1.p02.nsone.net accountdynamics.ai
Replace `@dns1.p02.nsone.net` with the name server listed under the Nameservers tab in your zone.
After the lookup is performed, you should receive an answer that looks similar to the following:
; <<>> DiG 9.10.6 <<>> A @dns1.p02.nsone.net accountdynamics.ai ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43096 ;; flags: qr aa rd; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1 ;; WARNING: recursion requested but not available ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 1232 ;; QUESTION SECTION: ;accountdynamics.ai. IN A ;; ANSWER SECTION: accountdynamics.ai. 3600 IN A 220.127.116.11 accountdynamics.ai. 3600 IN A 18.104.22.168 ;; Query time: 67 msec ;; SERVER: 22.214.171.124#53(126.96.36.199) ;; WHEN: Wed Oct 14 16:25:37 CDT 2020 ;; MSG SIZE rcvd: 79 </>></>>
And that’s all there is to DNS round-robin load balancing. However, that’s not where it has to end. Your NS1 Developer Account has a lot of the same next-gen features that our enterprise DNS and Application Traffic Steering platform has, including one filter chain.
NS1 Filter Chain
As mentioned earlier, traditional DNS load balancing was susceptible to reliability issues; however, your NS1 Filter Chain allows you to easily make a series of intelligent real-time decisions based on the health of your network topology, prodding your users with the best possible answer for every single request.
When NS1 receives a DNS query, we first look up the list of potential answers and then apply the filter chain to that list before serving an answer. Each Filter Chain takes a list of DNS answers as inputs and then performs a simple transformation that we can use to remove down servers from the list.
From your NS1 dashboard, open your A record again, and under “Filter Chain” click “Create Filter Chain.”
Under “Healthchecks” drag “Up” to the “Add Filters Here” section. Next, since we deployed our second instance to San Francisco, let’s add “Geotarget Regional” to our chain, and finally click “Save Filter Chain.”
Regardless of your goal, always place “Up” as the first step in your filter chain.
Congrats! Today you load-balanced your Go app.