concept

CDN

CDN, short for Content Delivery Network, is a virtual distributed Network based on bearer Network, which can intelligently cache source Content (including all kinds of dynamic and static resources) to nodes servers all over the world. This not only facilitates users to obtain content nearby, improves the speed of access to resources, but also shares the pressure of the source site.

CNAME, A record, NS record

The Domain Name System (DNS) converts Domain names into IP addresses. To complete the transformation, the DNS database needs to maintain relevant data, which is called Resource Records (RR). There are many types of resource records, such as A, NS, SOA, CNAME, and PTR records.

The one that most people touch is the A (Address) record. A Record is A mapping record from A domain name to an IP address. The CNAME (Canonical Name) record is a mapping record from domain Name to domain Name. It plays an important role in THE CDN technology, and achieves the decoupling of business domain name and CDN system domain name. If A domain name is configured with A record, DNS will resolve it to the IP address specified by A record. If a domain name is configured with a CNAME record, DNS will resolve it to another domain name specified in the CNAME record. A record and CNAME record are mutually exclusive and cannot exist at the same time.

The NS record is related to the DNS Server. It specifies which DNS Server should resolve the domain Name. Generally, the DNS server specified through NS records is called the authoritative DNS server of the domain name.

Speed up the domain name

Accelerated domain name Indicates a domain name that requires CDN acceleration. Acceleration domain is also a domain name. Accelerated domain name general configuration CNAME record, pointing to the CDN node. Common domain name Common configuration A Record pointing to the service server that provides services.

The source station

A business server that provides raw resources (resources accelerated using CDN), which can be specified as a domain name or IP address.

back

If the CDN node does not cache resources or the cache resources have expired, the CDN node returns to the source site to obtain resources and returns them to the client.

The working principle of

Suppose I set up a web site with the domain name www.tt.com and the user visits the home page link as www.tt.com/idx.html. In order to relieve the pressure of the server and speed up the access, we decided to use Ali Cloud CDN service. To better understand the working principle, let’s first understand the access process of CDN.

Access to the process

The main access steps are as follows:

  1. Apply for an accelerated domain name from a domain name provider:js.tt.com.
  2. Add accelerated domain name to Aliyun CDN platformjs.tt.comAnd set the source domain name towww.tt.com.
  3. Ali Cloud CDN platform automatically allocates oneCNAMEDomain name:js.tt.com.ali.com.
  4. Go to the domain name provider for the accelerated domain namejs.tt.comaddCNAMERecord, whose value is obtained in the previous stepCNAMEDomain name:js.tt.com.ali.com.

To further elaborate on the above steps:

  • In order to use the CDN, you must apply for an accelerated domain name as an entry point to use the CDN.
  • Accelerated domain name configuration isCNAMEThe value is provided by the CDN platformCNAMEDomain name, theCNAMEThe domain name points to a CDN node.
  • When adding an accelerated domain name, you need to configure the source domain name. Therefore, the CDN platform saves the mapping between the accelerated domain name and the source domain name.
  • The format of CNAME domain name is generally: < accelerator domain name > + < supplier main domain name >.

CDN system architecture

In terms of functions, a typical CDN system consists of distribution service system, load balancing system and operation management system. The distribution service system is responsible for responding, caching, and synchronizing resources. The load balancing system schedules user requests. Operation management system is responsible for operation demand management and network system management.

In terms of node distribution, CDN system is mainly divided into edge layer and center layer. The edge layer is distributed at the edge of THE CDN network to provide users with nearby access services. The central layer is responsible for resource synchronization and operation management. The central layer stores the configuration information of the accelerator domain name, such as the source domain name, and caches various resources under the accelerator domain name. If the edge layer node fails to hit the cache, a request needs to be sent to the center layer node. If the central layer node fails to match the cache, it needs to search for the corresponding source domain name and send a request to the source domain name. The resource requested by the user is then returned and cached layer by layer.

Access to the process

The flow of user A’s first access is as follows:

  • Step 1 accesses the accelerator domain, not the source domain.
  • Step 3 returns the CNAME domain name.
  • Step 5 Return the IP address corresponding to the CNAME domain name, pointing to the CDN edge layer node.
  • The requested URL (or Referer) for step 6 remainsjs.tt.com/idx.html.
  • Step 7 requests the central tier node with the URL from Step 6 as a parameter.
  • Step 8 Query the configuration data to obtain the domain name of the source site and send a request to the source site. The service server is the source of CDN. For simplicity, the procedure of querying A records from the DNS server is omitted.
  • The domain name of the URL changes throughout the process, but the URL path does not.

The second visit process of user A is shown in Figure 2:

Further clarification is needed:

  • Because the local DNS client has the cache to speed up domain name resolution, there is no need to query the DNS server.
  • Since the CDN edge layer node has the cache of corresponding resources, there is no need to request resources up.

The flow of user B’s first visit is shown in Figure 3:

Further clarification is needed:

  • Users A and B are geographically far apart and use different edge layer nodes. Therefore, the edge layer node does not cache corresponding resources and needs to request resources from the central layer node.
  • The central tier node has a cache of this resource, so there is no need to go back to the source.

Proximity principle

How does a CDN system achieve proximity?

The CNAME domain name is provided by the CDN provider and the CDN provider has the right to configure the CNAME domain name. The CDN provider sets the NS record of the CNAME domain name as its DNS server. In this way, the DNS server set up by the CDN provider is requested when resolving the CNAME domain name. The CDN provider implements load balancing in the DNS server and returns THE IP address of the edge layer node close to the user. This enables proximity access. In Figure 1, step 4 is queried to the Aliyun DNS server, which will return the IP addresses of multiple nearby available CDN edge nodes based on information such as geographic location and health status. The DNS client selects one of the IP addresses as the resolution result, usually the first one.