DNS-Based GSLB: A Comprehensive Site Load Balancing Solution

EdgeOne-Product Team
Aug 13, 2024

Currently, various scheduling mechanisms are applied to the GSLB system of CDN, among which the most common one is GSLB based on DNS resolution. There are also GSLBs based on application layer protocol redirection and GSLBs based on routing protocol. In this article, we will mainly introduce GSLB based on DNS resolution.

Traditional Network vs Content Delivery Network

Accessing Traditional Network Services

  1. The user enters the website domain www.test.com in the browser, and the browser requests the local DNS server to resolve the domain:
  • If the local DNS server has cached the domain resolution result, it directly responds to the user's resolution request;
  • If the local DNS server does not have a cached resolution result for the domain, it recursively requests resolution from the entire DNS system, and after receiving the response, it provides the result to the browser.
  1. Once the browser obtains the domain resolution result, it gets the IP address "1.1.1.1" of the corresponding service device.
  2. The browser sends a content request to the server.
  3. The server delivers the requested content to the browser.

Accessing CDN Services

  1. When a user makes an access request for an image resource (e.g., 1.jpg) at www.test.com, a domain name resolution request will be initiated to the local DNS.
  2. When the local DNS resolves www.test.com, it will find that CNAME www.test.com.cdn.dnsv1.com has been configured, so the resolution request will be sent to Tencent DNS (GSLB), the proprietary scheduling system of Tencent Cloud that will assign the optimal node IP for the request.
  3. The local DNS receives the resolved IP returned by Tencent DNS.
  4. The user receives the resolved IP.
  5. The user makes an access request for 1.jpg to the received IP.
  6. If the CDN node corresponding to the IP has already cached 1.jpg, data will be directly returned to the user (10) and the request will end. Otherwise, the CDN node will initiate a request for 1.jpg to the origin server (6, 7, and 8). After receiving the resource, the CDN node will cache it (9) based on the caching policy configured and return it to the user (10) to end the request.

Why is DNS Needed?

The Internet, which connects hosts in the network, needs its own set of rules. The position of a host on the Internet is identified by an IP address, and each host needs to have a unique IP address. Different hosts are identified through this unique IP.

However, we rarely access websites by entering IP addresses in real life because they are hard to remember. For instance, to visit Tencent's homepage, you would enter edgeone.ai instead of an IP like 1.1.1.1. Therefore, host name identifiers, such as edgeone.ai, were introduced.

While machines prefer simple numerical IPs, people use host names, and the conversion between the two is the mapping relationship between host names and IP addresses.

To implement this function, each host stores the conversion table from host identifiers to IP addresses in a database file called hosts. Nearly all modern operating systems still have this host file, but its content has become less (as most of its functions have been replaced by DNS servers).

We can still query our host file today. However, as the network scale continues to expand and the number of access hosts continues to increase, the feasibility of this centralized management of host names and IP address mapping relationships gradually decreases.

To facilitate maintenance and management, timely update, and synchronization of mapping relationships across the network, the DNS specification was proposed, which eventually evolved into the DNS system we talk about today.

GSLB Working Mechanism Based on DNS Resolution

What is GSLB?

GSLB stands for Global Server Load Balancing. It is a technique used to distribute traffic across multiple servers or data centers located in different geographical locations. The primary goal of GSLB is to ensure high availability, reliability, and optimal performance of web applications or services by efficiently routing user requests to the best-performing server or data center based on factors such as server load, user location, and network latency. This helps minimize response times, reducing the risk of server overloading, and providing a seamless user experience.

DNS-based GSLB solutions involve deploying load-balancing devices within the DNS system. When users initiate any application connection requests, they must first obtain the server's IP address through the DNS system. DNS-based GSLB makes intelligent decisions during the DNS response process, returning the best server IP address to the user. From the user's perspective, the entire application flow does not change with or without GSLB involvement.

How does DNS-based GSLB Work?

There are various methods to implement GSLB based on DNS resolution, with the following three being the most common:

Implementing Load Balancing through CNAME

CNAME is an alias for a domain name. When a server obtains a CNAME record, it replaces the searched domain name with the alias in the record and then queries the A record of the alias to obtain the corresponding IP address.

The process involves defining the GSLB hostname as the alias for the authoritative DNS server of the queried domain name and adding multiple A records to the GSLB hostname, each corresponding to the IP address of a different server.

This way, the local server returns multiple IP addresses as the domain query result to the client and polls these IPs. For example, if the DNS returns two IPs, 5.5.5.5 (A) and 6.6.6.6 (B), the client will first attempt to access the Shenzhen IP, and if the request fails, it will initiate a request to the (B) IP. When the next user requests the same domain name resolution, the authoritative domain name server will put the (B)  IP first in the response information. The client will then first attempt to initiate a request to (B), achieving load balancing between the two servers.

Load Balancer as Authoritative DNS Server

This method involves using the load balancer as the authoritative DNS server for a domain namespace. In this way, the load balancer accepts all DNS requests for the domain (the load balancer replaces the authoritative DNS server for resolution, and all DNS requests are sent to the load balancer regardless of whether the website the user visits requires domain resolution). Thus, load balancing can be achieved through domain resolution based on preset policies.

Load Balancer as Proxy DNS Server

This method involves registering the load balancer as the authoritative DNS server for a domain namespace, with the actual authoritative domain name server deployed behind the load balancer. All DNS requests first arrive at the load balancer, which forwards them to the real authoritative DNS server. The load balancer then modifies the response information returned by the authoritative DNS server to achieve load balancing.

FAQs

To better understand the differences between accessing content through a CDN and traditional network access, consider the following two questions:

Why use a CNAME alias mechanism? What are the benefits?

The reason for setting a CNAME in CDN business scenarios is usually due to intelligent resolution, where IPs resolved in different regions are different. Imagine that when using a CDN service, the provider gives you an IP. If the provider changes the IP address one day, the domain name corresponding to the IP must also be modified. If you use a CNAME, you only need to resolve it again. Therefore, if IPs change frequently, it is recommended to use CNAME alias resolution. If IPs do not change frequently, you can use A records to resolve directly to the IP.

Can you access the site directly using the alias after CNAME?

This is not possible because the domain name after CNAME is used to find the IP and cannot be accessed directly. If you try to access the CNAME domain directly, you may encounter a 504 page. 

Many people believe that after CNAME-ing a domain (sub.domain1.com) to another domain (domain2.com), you can access sub.domain1.com to get the content of domain2.com. This confuses the difference between resolution and binding and conflates CNAME with redirection. CNAME can only ensure that the resolution of sub.domain1.com is synchronized with domain2.com. If it is a shared IP host, you still cannot access the website content without binding.

Tencent EdgeOne

Tencent EdgeOne's traffic scheduling management tool implements intelligent parsing and scheduling across multiple CDNs, supporting custom traffic scheduling strategies between origin servers and multiple service providers. This ensures smooth gray-scale migration and flexible allocation of traffic, guaranteeing high service availability. It has the following advantages:

  1. Easy management: With just three steps - selecting a domain, adding a service provider, and adding a scheduling strategy - you can easily implement traffic scheduling management.
  2. Quick access: Users only need to add the CNAME record assigned by EdgeOne to their DNS resolver to quickly access the service.
  3. Multiple scheduling modes: Supports proportional and regional scheduling modes, which can be combined to meet diverse requirements.
  4. Wide coverage of scenarios: Supports both origin servers and CDN providers as scheduling service providers, catering to scenarios such as gray-scale switching and simultaneous use of multiple service providers.

We have now launched a free trial, click here or contact us for more information.