September 25, 2022

COSFONE

Networking, PBX, IT, DIY Solution

How to use DNS parsing to achieve load balancing of websites?

5 min read

How to use DNS parsing to achieve load balancing of websites?



How to use DNS parsing to achieve load balancing of websites?

When the number of visits to the website is large, load balancing will be considered.

This is also the basic skill of every architect. Its basic status is equivalent to talking and singing in cross talk.

Whether you live well or not depends on this.

The traditional load balancing idea is a single point, whether you are hardware or software, it is basically the same principle

How to use DNS parsing to achieve load balancing of websites?

For general needs, such an architecture can basically solve the problem. And it’s relatively simple to maintain. Well, most companies do that too.

Limitations of traditional thinking

As shown in the figure above, traditional thinking also has obvious limitations.

That is to say, the response speed of the website is largely limited to the capacity of the load balancing node, and once the load balancing node itself hangs up, the entire website will be completely paralyzed.

The back-end services can be scaled horizontally, but for a single node, even if you increase the configuration of the machine, there is a limit, and this does not conform to the development law of Internet technology.

How CDN works?

As a major infrastructure that carries most of the traffic on the Internet, CDN‘s solution to load offloading is very inspiring

How to use DNS parsing to achieve load balancing of websites?

As can be seen from the above figure, the user’s access is shunted, and all requests are no longer aggregated to one node, but are shared on each appropriate node, so that even if there is a single point of failure, it will only affect To some users, and we can also use other means to do failover.

The same approach can also be borrowed from the traditional BS architecture.

We can also directly distribute user requests to different servers without going through a unified node.

What is this diversion through? The answer is DNS !

Do you know how DNS works?

Most people may use DNS every day but don’t know its basic principle.

You may know that we need to query the DNS server to access the Internet, which is the following thing

We just need to ask it the IP address corresponding to the domain name.

But is it really that simple? How does it know the IP address corresponding to this domain name?

In fact, the DNS system is a typical tree structure.

The DNS server shown in the figure above should actually be called a DNS cache query server, which is designed to reduce the load of DNS query on the Internet.

If your request does not hit the cache, the cache server will perform a standard query by itself, and then cache the result. In short, it starts from the root server and asks level by level.

We used to talk about the importance of the root server, which is actually reflected here.

It reserves the right to interpret the beginning of all domain names.

Magical Right of Interpretation Mechanism (SOA)

As mentioned above, the root server has the right to interpret all domain names, but if you ask the root server, it will not directly tell you the final answer.

Because if it were to store all the records, it would be too tiring and the load and overhead would be staggering. So what will it tell you?

It tells you who to ask, which means it authorizes the next server to answer your questions. personify the process

  1. me: root, root tell me, how does segmentfault.com go?
  2. root: Oh, you can ask the DNS server of .com, the address is xxxxxx
  3. Me: .com, .com tell me, how about segmentfault.com?
  4. .com: Oh, you can ask the DNS server (DNSpod or the like) of segmentfault.com, the address is xxxxxx
  5. me: DNSpod, DNSpod tell me, how does segmentfault.com go?
    DNSpod: take xxxxxx, let’s go

How to use DNS parsing to achieve load balancing of websites?

Basic Principles of DNS Load Balancing

Knowing the above process, we get two basic conclusions

  1. The DNS system itself is a distributed network, it is relatively reliable, at least much more reliable than your website itself
  2. The final interpretation of DNS can be controlled by ourselves

With these two conclusions, the rest is simple, we just need to make a fuss about the final interpreted query result.

Simply put, it is to return all your server addresses to the user according to the frequency set by their own needs.

Taking github.com as an example, we first get its SOA server (because the DNS cache query server will cache the results, if you directly query the domain name, it will return the same result every time), the DNS domain name server of .com is also 13 Servers, they are [a-m].gtld-servers.net, we just pick one to find the SOA of github.com

How to use DNS parsing to achieve load balancing of websites?

OK, we have obtained four SOA servers ns[1-4].p16.dynect.net, and then choose any one to ask the corresponding record of github.com, by the way, try a few times to see if the final ip address will change

We have queried twice here, and the attention ANSWER SECTIONpart returns two results, one is 192.30.252.129and one is 192.30.252.128.

This is the use of DNS to achieve load balancing, and your final access will reach different ip addresses.

Which DNS service providers support load balancing?

This is a relatively advanced service, which is generally not supported by the DNS servers of domain name registrars. At present, I know that the service providers that support it are:

  1. AWS Route 53
  2. NSONE
  3. Dyn
  4. dnspod

Among them, 1 and 4 are what we are already using, and the effect is ideal.


Summary:

In fact, DNS can play far more tricks than these, can also do failover, can also be resolved by region and so on.

Domain names have existed since the birth of the Internet, but the research on it and the derived usage methods have just begun to be discovered.

With the improvement of everyone’s use of the Internet, such technologies will definitely increase.



Copyright © All rights reserved. | Newsphere by AF themes.