跪拜 Guibai
← Back to the summary

CDN Architecture: How Edge Nodes and GSLB Fix the Latency That HTTP Can't

Why do we need network acceleration?

CDN (Content Delivery Network or Content Distribution Network) is called "内容分发网络" in Chinese.

Why do we need network acceleration?

You might ask: HTTP transfer speed isn't bad, and there's even better HTTP/2. Why do we need an extra CDN to accelerate? Isn't it redundant?

Here we must consider the problems encountered in real life. You know the speed of light is finite. Although it's 300,000 km per second, that's just the upper limit in a vacuum. In actual cables and optical fibers, the speed drops to about two-thirds of that, i.e., 200,000 km/s. Thus, transmission delay caused by geographic distance becomes noticeable.

For example, the straight-line distance from Beijing to Guangzhou is about 2,000 km. At 200,000 km/s, sending a request is 10 ms one-way, 20 ms round-trip. Even if you do nothing, this "hard" delay is unavoidable. Also, don't forget that the internet is logically a big network, but physically it's composed of many small networks. Among them, there is the problem of "interconnection" between small networks. A typical example is the networks of various telecom operators, such as the three major ones in China: Telecom, Unicom, and Mobile.

image

Communication within these small networks is smooth, but between networks there are only a few interconnection points. If you're on network A and the website is on network C, then the transfer must be "cross-network", sharing a "single-plank bridge" with thousands of other users. Bandwidth is limited, and how much you get depends on luck. Also, there are many routers and gateways. Every time data passes through a node, it stops, parses and forwards at layer 2 and layer 3, which also consumes time and adds latency. Put these factors on a global scale, and the impact of geographic distance, operator networks, and router forwarding increases exponentially. Imagine visiting a San Francisco website from Beijing. You cross half the globe. How many hops and how much delay will that add?

The result is that with only existing HTTP transfer methods, most websites would be slow and have poor user experience.

What is CDN?

It is a network application service specifically designed to solve slow network access over "long distances".

CDN has three key words: "content", "distribution", and "network".

First, let's look at the meaning of "network". The core principle of CDN is "access nearby". If users can get data within a few tens of kilometers locally, latency becomes almost zero.

So CDN invests heavily in building data centers in major cities across the country and even globally, deploying many nodes with high storage and high bandwidth, creating a dedicated network. This network spans operators and regions. Although internally it's divided into multiple small networks, they are connected by high-speed dedicated lines, a true "information superhighway" where congestion is essentially non-existent.

With this high-speed dedicated network, CDN "distributes" the "content" of the origin server using "cache proxy" technology. Using "push" or "pull" methods, content is cached level by level to every node of the network.

Thus, when users go online, they don't directly access the origin server; instead, they access a CDN node "nearest" to them, called an "edge node", which is actually a proxy server that caches origin content. This saves the time cost of "traveling long distances" and achieves "network acceleration".

image

In the CDN domain, "content" actually refers to the "resources" in the HTTP protocol, such as hypertext, images, videos, application installation packages, and so on.

Resources are divided into "static resources" and "dynamic resources" based on whether they can be cached. "Static resources" have content that is "static and unchanged"; whenever you access them, they are the same, like images and audio. "Dynamic resources" have content that "changes", generated by backend services, and differ on each access, like product inventory or Weibo follower counts.

Clearly, only static resources can be cached for acceleration and local access. Dynamic resources can only be generated in real time by the origin server; caching them is meaningless. However, if a dynamic resource specifies "Cache-Control" to allow caching for a short time, it becomes "static" during that period and can be cached and accelerated by CDN.

"We don't produce content; we just move it."

CDN's Load Balancing

Let's look at how CDN actually runs. It has two key components: global load balancing and a caching system.

Global Server Load Balancing, usually abbreviated as GSLB, is the "brain" of CDN. Its main job is to select the "best" node in the CDN private network to provide service when a user connects. It solves how users find the "nearest" edge node and load balances the entire CDN network.

image

The most common implementation of GSLB is "DNS load balancing", but GSLB is slightly more complex.

Without CDN, the authoritative DNS returns the actual IP address of the website's own server, and the browser connects directly to the website after receiving the DNS resolution result.

But with CDN, the authoritative DNS returns not an IP address but a CNAME (Canonical Name) alias record, which points to the CDN's GSLB. It's somewhat like "Alt-Svc" in HTTP/2, telling the outside: "I can't give you the real address for now; go check somewhere else."

Because the IP address isn't obtained, the local DNS makes another request to the GSLB, entering the CDN's global load balancing system for "smart scheduling". The main criteria are:

  1. Look at the user's IP address, look up the geographic location, and find the relatively nearest edge node;
  2. Look at the user's operator network and find an edge node on the same network;
  3. Check the load of edge nodes and find nodes with lighter load;
  4. Others, such as node "health", service capability, bandwidth, response time, etc.

GSLB combines these factors with a complex algorithm and finally picks a "most suitable" edge node, returning its IP address to the user. The user can then "locally" access the CDN cache proxy.

CDN's Cache Proxy

The caching system is another key component, the "heart" of CDN. If the caching system's service capability is insufficient to meet user needs, no matter how good the GSLB scheduling algorithm is, it's useless. But internet resources are infinite, and no matter how strong a CDN vendor is, it cannot cache everything. So the caching system must selectively cache the most commonly used resources.

There are two key CDN concepts: "hit" and "origin fetch". A "hit" means the resource the user requests is exactly in the cache and can be returned directly to the user. "Origin fetch" is the opposite: the cache doesn't have it, and a proxy must fetch it from the origin server.

Accordingly, there are two metrics for measuring CDN service quality: "hit rate" and "origin fetch rate". Hit rate is the ratio of hit count to total access count; origin fetch rate is the ratio of origin fetch count to total access count. Obviously, a good CDN should have a higher hit rate and a lower origin fetch rate. Current commercial CDNs have hit rates above 90%, effectively multiplying the origin server's service capacity by more than 10 times.

Summary

CDN has been around for over 20 years. Early CDNs had simple functions and could only accelerate static resources. With the rise of Web 2.0, HTTPS, video, live streaming and other new technologies and businesses, it has evolved, adding many new features such as SSL acceleration, content optimization (data compression, image format conversion, video transcoding), resource anti-leeching, WAF security protection, and so on.

Because objective geographic distance exists, direct access to websites is slow, so CDN came into being. CDN builds a national and global private network, allowing users to access edge nodes in the network nearby, reducing transmission delay and achieving website acceleration. GSLB is the "brain" of CDN, using DNS load balancing to intelligently schedule edge nodes. The caching system is the "heart", using HTTP cache proxy technology: if a cache hits, it returns to the user; otherwise, it fetches from the origin.