1. Concept
CDN (Content Delivery Network) is a network composed of proxy servers and their data centers distributed in different geographical locations:
A content delivery network or content distribution network (CDN) is a geographically distributed network of proxy servers and their data centers.
Hoping to provide services to users nearby in spatial distance to improve availability and performance:
The goal is to provide high availability and high performance by distributing the service spatially relative to end-users.
P.S. Spatial distance is reflected in network transmission as hops, the more hops from client to server, the farther the distance, generally the greater the latency
2. Function
CDN is generally used to host web resources (including text, images and scripts), resources available for download (media files, software, documents, etc.), applications (e-commerce, portals, etc.), as well as streaming media and social media websites, accelerating access to these resources
In terms of performance, the role of introducing CDN lies in:
-
Content received by users comes from the nearest data center, lower latency, faster content loading
-
Part of resource requests are outsourced to CDN, reducing server load
On one hand, it shortens the distance between content and end users, on the other hand, content is not obtained directly from the server, saving server computing resources, sharing origin server pressure
In terms of security, CDN helps defend against DDoS, MITM and other network attacks:
-
DDoS (Distributed Denial of Service): By monitoring and analyzing abnormal traffic, limiting its request frequency
-
MITM (Man-In-The-Middle): Full-link HTTPS communication from origin server to CDN node to ISP (Internet Service Provider)
Additionally, as a basic cloud service (IaaS), CDN also has advantages in resource hosting, on-demand expansion (able to cope with traffic peaks) and other aspects:
This reduces content providers' infrastructure requirements, and lets them deploy or expand services more quickly and easily.
P.S. For more information about IaaS, PaaS, SaaS, see [IaaS-PaaS-SaaS Definition](/articles/iaas-paas-saas 定义/)
3. Structure
In terms of topology, CDN is divided into two types: Scattered CDN and Consolidated CDN
Scattered CDN

Deploy as many servers as possible around the world, called Scattered CDN:
Scattered CDNs aim to have as many servers scattered around the world as possible.
Early CDN used a large number of medium-to-low performance servers to densely fill selected geographical areas, these small nodes are easy to deploy, especially suitable for low-connectivity areas
With the continuous improvement of global connectivity, the benefits of reducing physical distance gradually decrease, and the maintenance costs of a large number of nodes also become prominent, so Consolidated CDN emerged
Consolidated CDN

Consolidated CDN has only a small number of nodes in major data centers, but the nodes are more powerful, including network, throughput and DDoS resistance:
Consolidated CDNs have fewer points, but bigger ones built for network performance, throughput, and DDoS resistance.
This centralized structure helps improve overall response capability, providing more control for users and network operators, but deployment is relatively complex, and effects are poor in low-connectivity areas
4. Classification
CDN is divided into Push CDN and Pull CDN according to content distribution method
The former has the content server push content to CDN cache in advance, the latter has CDN pull target resources and cache them when users access content
Push CDN
Every time content changes, upload new content to Push CDN. Since only newly added content and changed content need to be uploaded, the traffic used for transmission is relatively small, but the content to be stored is relatively large
Therefore, Push CDN is suitable for low-traffic sites, or sites with infrequent content updates, content is placed on CDN at once, no need to periodically re-pull. If traffic burden is already heavy, or content changes frequently, Push CDN will bring additional pressure to the server
Pull CDN
Pull CDN does not require manual upload, automatically pulls new content from server when users first access, and caches it. On-demand caching saves CDN storage space, but re-pulling when files expire or when no changes occur also causes unnecessary traffic overhead
Therefore, Pull CDN is suitable for high-traffic sites, only caching recently used (most popular) content, once configured can cache content on demand, lower maintenance costs
5. Principle
Involves several terms:
-
Origin server: Server providing content (data) source
-
Edge server: Server used to cache content from origin server
-
Point of Presence (PoP): Physical location where edge servers are located, there may be multiple edge servers at one point of presence
-
CDN Reverse Proxy: Forwards user requests to origin server, and caches responses from origin server, used for Pull CDN
-
Back-to-source: When CDN node has not cached requested resource or cached resource has expired, go back to origin to get resource, return to client
Working Principle
Taking Pull CDN as an example, when users in a specific region access resources for the first time, get from origin server, after content responds to user, resource will be cached on edge server in that region, if users in the same region request the same resource again, respond from edge server:

P.S. Can distinguish whether content response comes from origin server or CDN cache through specific fields in response header, for example:
-
X-Cache: HIT: Hit cache, response content comes from CDN cache -
X-Cache: MISS: Miss cache, response content comes from origin server
Implementation Principle
In implementation, hand over subdomain resolution authority to CDN through CNAME record, then through geographic location proximity-based routing strategy, map requests to edge server closest to user:
For Push CDN, edge server only provides cache service, return 404 if cache miss, while for Pull CDN, edge server provides reverse proxy service, go back to origin to get when cache miss
No comments yet. Be the first to share your thoughts.