How to use DNS parsing to achieve load balancing of websites?
5 min readHow to use DNS parsing to achieve load balancing of websites?
- Huawei Mate 60 Pro Makes Satellite Calls: Only US$0.18/minute
- Huawei Mate60 Pro: First Smart Phone Supports Satellite Calls
- 14000 cores + 450W: RTX 4080 graphics card perfectly replaces the RTX 3080
- Big upgrade: The difference between Bluetooth 5.0 and 5.2
- Geeks Disappointed that RTX 4080/4090 doesn’t come with PCIe 5.0
- What are advantages and disadvantages of different load balancing?
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
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
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
- me: root, root tell me, how does segmentfault.com go?
- root: Oh, you can ask the DNS server of .com, the address is xxxxxx
- Me: .com, .com tell me, how about segmentfault.com?
- .com: Oh, you can ask the DNS server (DNSpod or the like) of segmentfault.com, the address is xxxxxx
- me: DNSpod, DNSpod tell me, how does segmentfault.com go?
DNSpod: take xxxxxx, let’s go
Basic Principles of DNS Load Balancing
Knowing the above process, we get two basic conclusions
- The DNS system itself is a distributed network, it is relatively reliable, at least much more reliable than your website itself
- 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
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:
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.
- DIY a PBX (Phone System) on Raspberry Pi
- How to host multiple websites on Raspberry Pi 3/4?
- A Free Intercom/Paging system with Raspberry pi and old Android phones
- DIY project: How to use Raspberry Pi to build DNS server?
- Raspberry Pi project : How to use Raspberry Pi to build git server?