What is CDN

The full name of a CDN is Content Delivery Network. By adding a new CACHE layer to the existing Internet, the content of the website is published to the node closest to the user’s “edge” of the network, so that the user can get the required content nearby and improve the response speed of the user’s access to the website. From the technical comprehensive solution due to the network bandwidth is small, user access to large, unequal distribution of outlets, improve the user access to the site response speed.

In simple terms, the working principle of CDN is the resource cache will stand you source into a world of CDN node, when the user requests resources, returned to the nearest node cache resources, without the need for each user’s request to return to your source all stand for, to avoid network congestion, reduce the pressure on the source station, speed and experience to ensure users to access resources.



The optimization effect of CDN on the network is mainly reflected in the following aspects

  • Solve the “first kilometer” problem on the server side
  • Alleviating or even eliminating the impact of the bottleneck between the interconnection of different operators
  • Reduce the export bandwidth pressure of the provinces
  • Takes the pressure off the backbone
  • Optimized the distribution of hot content online

Two, CDN working principle

Traditional access process



As can be seen from the figure above, the process for users to access the website without CDN cache is:

  • The user enters the domain name, and the operating system queries the IP address of the domain name from LocalDns
  • LocalDns queries ROOT DNS for the authorization server for the domain name (assuming that the LocalDns cache has expired)
  • ROOT DNS replies the domain name authorization DNS record to LocalDns
  • After obtaining the authorized DNS record of the domain name, LocalDns continues to query the IP address of the domain name from the authorized DNS
  • Domain name Authorization DNS queries domain name records and replies to LocalDns
  • LocalDns replies the obtained domain name IP address to the client
  • After obtaining the domain name IP address, the user accesses the site server
  • The site server responds to the request and returns the content to the client

CDN access procedure



From the figure above, we can see that the access process of the website using CDN cache becomes:

  • The user enters the domain name, and the operating system queries the IP address of the domain name from LocalDns.
  • LocalDns queries ROOT DNS for the authorization server for the domain name (assuming that the LocalDns cache has expired)
  • ROOT DNS replies the domain name authorization DNS record to LocalDns
  • After obtaining the authorized DNS record of the domain name, LocalDns continues to query the IP address of the domain name from the authorized DNS
  • Domain name Authorization After the DNS queries the domain name records (usually cnames), the DNS responds to the LocalDns
  • After obtaining the domain name record, LocalDns queries the intelligent DNS for the IP address of the domain name
  • Intelligent scheduling DNS responds the most suitable CDN IP address to LocalDns based on certain algorithms and policies (such as static topology and capacity)
  • LocalDns replies the obtained domain name IP address to the client
  • After obtaining the domain name IP address, the user accesses the site server
  • The CDN node server responds to the request and returns the contents to the client. (On the one hand, the cache server saves the data locally for future use, and on the other hand, it returns the obtained data to the client to complete the data service process)

Based on the above analysis, it can be seen that in order to realize transparent access to common users (no setting is required for the client after using the Cache), DNS (domain name resolution) is required to guide users to access the Cache server, so as to realize transparent accelerated service. Since the first step for a user to access a website is domain name resolution, modifying the DNS to guide the user to the site is the easiest and most effective way.

The components of a CDN

For the average Internet user, each CDN node is equivalent to a web server placed around it.

By taking over the DNS, the user’s requests are transparently directed to the nearest node, where the CDN server responds to the user’s requests just like the site’s original server. Because it is closer to the user, the response time is necessarily faster.

The CDN layer, circled by the dotted line in the figure above, is the layer between the client and the site server. Intelligent scheduling of DNS (e.g. 3DNS for F5)

  • Intelligent scheduling DNS is a key system in CDN service. When a user accesses a website that has joined the CDN service, the intelligent DNS is responsible for handling the domain name resolution request.
  • Through a set of pre-defined policies, the node address closest to the user is provided to the user at that time, so that the user can get fast service.
  • At the same time, it needs to keep communication with CDN nodes distributed in different places, track the health status, capacity and other information of each node, and ensure that user requests are allocated to the nearest available nodes.

Cache Function Service

  • Load balancing devices (e.g. LVS,F5 BIG/IP)
  • Content Cache server (e.g. Squid)
  • Shared storage

Three, the noun explanation

CNAME Record (CNAME Record)

CNAME is the alias (Canonical Name); It can be used to resolve A domain name to another domain name. When the DNS system queries the name on the left side of the CNAME, it will turn to the name on the right side of the CNAME and then search until the last PTR or A name. It will respond only after the query succeeds.

For example, if you have a server that holds a lot of data, and you use docs.example.com to access those resources, but you want documents.example.com to also access those resources, you can add a CNAME record to your DNS resolution service. When you point documents.example.com to docs.example.com and add that CNAME record, all requests to documents.example.com will be redirected to docs.example.com and get the same content.

CNAME domain name

When accessing CDN, after adding accelerated domain name in the CONSOLE of CDN provider, you will get a CNAME domain name assigned by CDN. You need to add CNAME record on your DNS resolution service provider and point your accelerated domain name to this CNAME domain name, so that all requests from this domain name will be forwarded to the CDN node. Achieve the effect of acceleration.

DNS

DNS is the Domain Name System, which means Domain Name resolution service. Its role on the Internet is to transform domain names into IP addresses that can be recognized by the network. People are used to memorizing domain names, but machines only recognize IP addresses. There is a one-to-one correspondence between domain names and IP addresses. The translation between them is called domain name resolution, which needs to be completed by a special domain name resolution server. For example, the www.baidu.com input when accessing the Internet will automatically be converted to 220.181.112.143.

Common DNS resolution service providers are: Ali Cloud resolution, Ten million network resolution, DNSPod, New network resolution, Route53 (AWS), Dyn, Cloudflare, etc.

Back to the source host

Back to source Host: The back to source host determines the specific site to which the source request is sent.

Example 1: If the source site is www.a.com and the return host is www.b.com, the actual return source is the IP address resolved from ‘www.a.com and the corresponding site www.b.com on the host

Example 2: The source IP address is 1.1.1.1, and the source host is www.b.com. In this case, the actual source IP address is www.b.com on the host 1.1.1.1

The agreement back to the source

The protocol used to access the resource is the same as that used by the client to access the resource. That is, if the client requests the resource in HTTPS mode and the CDN does not cache the resource, the CDN uses the same HTTPS mode to obtain the resource from the source. Similarly, if the client uses HTTP for the request, the CDN uses HTTP for the request.