Location>code7788 >text

Use of DNS in Architecture

Popularity:900 ℃/2024-07-31 16:51:40

1 Introduction

DNS (Domain Name System) is a service that is a distributed database of domain names and IP addresses mapped to each other, enabling easier access to the Internet without having to memorize strings of IP addresses that can be read directly by machines.
Simply put, DNS is a system that converts the URLs we enter (e.g. ) into corresponding IP addresses (e.g. 192.0.2.1). This process is automatic and transparent. After the user enters the URL in the browser, the browser will initiate a query request to the DNS server, which will analyze the corresponding IP address according to the domain name, and then the browser will access the target server according to this IP address.

2 Realization principle

The DNS system works roughly as follows:

2.1 Recursive Queries

When a client (e.g., a browser) needs to resolve a domain name, it first initiates a query request to a local DNS server (e.g., a DNS server provided by an ISP). If the local DNS server does not have records for the domain name in its cache, it will initiate a query to the root DNS server. The root DNS server will return the DNS server addresses for the top-level domains (TLDs, such as .com, .net, etc.). The local DNS servers then initiate queries to these top-level domain DNS servers, and the top-level domain DNS servers return the addresses of the next level DNS servers until the final IP address is found. This process recursively queries the local DNS servers until a result is found or the query is determined to have failed.

image

Recursive query is a query pattern in which the DNS server actively helps the host to query.

2.2 Iterative queries

Unlike recursive queries, in iterative queries, the local DNS server will initiate a query to the root DNS server after receiving the client's query request, but the root DNS server will not return the IP address directly, but the address of the next level DNS server. The local DNS server will initiate a query to this address again, and so on, until the final IP address is found. In this process, each DNS server is only responsible for returning the address of the next level DNS server, not the IP address directly.

Iterative querying, on the other hand, involves the client itself querying step-by-step until it gets a result or traverses all possible query paths.

2.3 Powerful domain name resolution

DNS not only supportsA records(which maps domain names to IPv4 addresses), and also supports theAAAA records(mapping domain names to IPv6 addresses),CNAME records(alias records that map a domain name to another domain name),MX Records(mail exchange record that specifies the mail server that handles mail for the domain) and many other record types to meet different needs.

3 Role in Internet architecture

Let's look at the entire LifeCycle of an Http request, from the client-side call to the server-side response, and the role of DNS.
image
The steps of the process are as follows:

  1. Client accesses domain name Requests to DNS servers
  2. The DNS server returns the IP address of the domain name: 10.88.0.1, which is the address of the proxy service Nginx.
  3. Client continues to access extranet IP 10.88.0.1 to link to Nginx
  4. Nginx is configured with n Service (multicopy mode) intranet IPs, such as192.168.0.100、192.168.0.101、192.168.0.102
  5. Nginx's load balancing polls IP Lists with a traffic scheduling policy such as RR
  6. The request ends up in a Service that processes it and gets the result of the calculation.

This is the most basic capability of DNS, so what else does he contribute to the Internet architecture besides DNS's A-record resolution?

3.1 Reverse proxies and dynamic extensions

A reverse proxy is a type of proxy server that sits between a server and a client. The client sends a request to the reverse proxy, which then forwards the request to a back-end server based on certain rules. The back-end server returns the response to the proxy server, which then forwards the response to the client. The reverse proxy is transparent to the client, the client does not need to know the address of the actual server, only the reverse proxy as the target server to send a request can be.
The user at Client only needs to rememberThis provides a lot of convenience for scaling, so the original architecture can be optimized for:

image

Configure multiple Nginx Service IPs for the same domain name. Whenever DNS resolution is requested, RR polls to return a different Nginx IP address, realizing the ability to dynamically scale.

3.2 Load balancing

DNS polling is a simple load balancing method that spreads user requests across servers by changing the order of IP addresses in the DNS resolution results. In our diagram above, Nginx takes on this layer of responsibility, and we can try dispensing with Nginx to see how it works!

image

It looks like it removes a layer of network requests, but there are some problems with this.

  1. Inability to achieve intelligent load balancing

This skill supports simple polling and cannot support smarterWeighted Round RobinIP HashLeast Connectionsiso-loading strategy

  1. Unable to achieve live probing and failover

When using Nginx as a reverse proxy, you can perform survival probing of the Service, and when the service hangs, perform traffic migration to achieve the goal of failover and stop loss.

3.3 Intelligent Routing and Acceleration

Smart DNS: Intelligent DNS can resolve user requests to the most suitable server based on the user's geographic location, network conditions and other factors, thus improving access speed and user experience.
CDN (Content Delivery Network): CDNs utilize DNS technology to resolve user requests to the nearest cache node to the user, thereby speeding up content delivery and reducing network latency.

As shown below, although Chaozhou is in Guangdong, it is obviously closer to Xiamen, so the traffic is distributed to the Xiamen server room:
image

image

4 Summary

  • Dynamically Extending the Reverse Proxy Layer
  • Supports load balancing in simple polling mode, but cannot probe and Fail Over.
  • Intelligent Dns Routing and CDN Acceleration