Explore DNS resolution
DNS server
In the real world, when you read news, place an online order, download a file or watch a live broadcast, you need to visit the target website by visiting the domain name, such as youtube.com, google.com, etc. You only need to remember the names of these websites, not their IP addresses, because IP addresses are harder to remember than website names. Therefore, you need a website/domain address book that acts as a DNS server.
DNS is very important in everyday life. Everyone online needs to access it, but at the same time, it's a very big challenge for it. If the DNS server fails, the entire Internet network will be shut down.
In addition, people online are distributed all over the world, and if everyone goes to the same place to access a certain server, the delay will be very large. Therefore, DNS servers must be set up to be highly available, highly concurrent and distributed .
So it should have a tree-like hierarchy like this:
- Root DNS Server: Returns the IP address of the top-level domain DNS server.
- Top-level domain DNS server: Returns the IP address of the authoritative DNS server.
- Authoritative DNS Server: Returns the IP address of the corresponding host.
DNS resolution process
To improve DNS resolution performance, many networks deploy DNS caching servers based on location. The DNS resolution process is as follows: (here is to visit google.com as an example)
- The client will make a DNS request to ask what the IP of google.com is, and it will first look up the IP address of google.com in the browser cache.
- The request will then be sent to the local DNS server. The local DNS server is automatically assigned by your Internet Service Provider (ISP), which is usually a router provided by your ISP.
- The local DNS server receives the DNS request from the client, and it looks up the IP address of google.com in its cache. If it can find the corresponding entry, it will return the IP address directly to the client. Otherwise, the local DNS server will ask its root nameserver: "Can you tell me the IP address of google.com"? As the highest-level DNS server, there are 13 root name servers in the world. It does not directly resolve domain names, but acts as a "guide".
- The root DNS server receives the local DNS request, finds that the suffix of the domain name to be searched is .com, and then tells the local DNS server: "Okay, since the domain name you are looking for is the suffix of .com , it is managed by .com. Here is the IP address of the top-level domain DNS server for the .com zone, go and ask it."
- The local DNS server turns to the top-level domain name server for the .com zone and requests the IP address of google.com. The top-level .com zone DNS servers again directed the request. It provides the IP address of the authoritative DNS server responsible for google.com.
- The local DNS server then turns to the authoritative DNS server and asks for the IP address of google.com. This time, the authoritative DNS server for google.com is the original source of the domain name resolution results. It returns the IP address of google.com directly to the local DNS server.
- The local DNS server then returns the IP to the client and caches it. At this point, DNS resolution is complete.
To summarize, I drew the following picture:
DNS load balancing
Internal load balancing
The DNS server performs internal load balancing first. For example, if the application wants to access the database, should the IP address of the database be configured in the application, or should the domain name of the database be configured?
Obviously, the domain name should be configured, because once the database is moved to another machine for some reason, if multiple applications are configured with this database, once the IP address changes, all of those applications will need to be reworked.
However, if a domain name is configured, the work is done by simply mapping the domain name to a new IP address in the DNS server, which greatly simplifies the operation and maintenance work.
On this basis, we can go further. For example, how to load balance among multiple applications accessing it? Just configure it as a domain name. In domain name resolution, we only need to configure the policy, this time the first IP is returned, and the second IP is returned next time to achieve load balancing.
global load balancing
To ensure high availability of our applications, they are often deployed in multiple computer data centers, each with its own IP address.
When a user visits a domain name, this IP address can poll multiple data centers. If a data center goes down for some reason, just delete the IP address corresponding to the data center in the DNS server. In this way, a certain degree of high availability can be achieved.
In addition, we definitely want users in New York to visit the data center in New York, and users in Seattle to visit the data center in Seattle, so that the customer experience will be very good, and the access speed will be super fast. This is the concept of global load balancing.
Let's see how it works, assuming there are multiple regions across the country, each with three availability zones.
- When a client wants to access app.metaleap.com, it needs to convert the domain name to an IP address to access, so it needs to request a local DNS resolver.
- The local DNS resolver first checks the local cache for this record. If there is, use it directly.
- If there is no local cache, you will need to request a local DNS server.
- The local DNS server also needs to check whether there is a local cache, and return if there is.
- If there is no local DNS, you need to recursively look up the top-level domain name server for .com from the root DNS server until you find the authoritative DNS server for metaleap.com and hand it over to the local DNS server. Authoritative DNS servers usually return real IP addresses.
For simple applications that do not require global load balancing, the authoritative DNS server of metaleap.com can directly resolve the domain name app.metaleap.com to one or more IP addresses, and then clients can use multiple IP addresses for polling to achieve simple load balancing.
However, for complex applications, especially large-scale applications across regions and data centers, a more complex global load balancing mechanism is required, which requires a dedicated device or server to do this - Global Load Balancer (GSLB, Global Load Balancer) Balancer).
In the DNS server of metaleap.com, generally by configuring CNAME, give app.metaleap.com an alias, such as app.vip.metaleap.com, and then tell the local DNS server to request GSLB to resolve the domain name, and GSLB is resolving the domain name In the process, you can achieve load balancing through your own strategy.
Two tiers of GSLB are plotted in the figure, the data center and the region. We want customers in different data centers to have access to resources in the same data center to increase throughput and reduce latency.
in conclusion
DNS is the address book of the online world. You can search for addresses through domain names. Because domain name servers are organized in a tree structure, domain name searches are recursive and cached to improve performance.
In the process of domain name and IP mapping, applications have the opportunity to perform domain name-based load balancing, which can be simple load balancing or global load balancing based on addresses, data centers, and regions.