2. CDN: Your "Global Courier Network"
2.1 Motivation for needing a CDN
Imagine you run an online store with servers in Shenzhen. Now a user in Beijing wants to access your images:
Without CDN: The request travels from Beijing → Hebei → Henan → Hubei → Hunan → Guangdong → Shenzhen, spanning over 2,000 kilometers—a round trip of over 4,000 kilometers. Network transmission alone takes tens of milliseconds, and it's even worse during network congestion.
With CDN: The request goes directly from Beijing to a Beijing CDN node (possibly in a Beijing Unicom data center). The distance shrinks from 2,000 km to 20 km, and latency drops from 50ms to 5ms.
This is the core value of CDN: bringing content closer to the user.
2.2 CDN Core Architecture
Edge Nodes: The "Courier Stations" Closest to Users
Edge nodes are the tier closest to users in the CDN network, typically deployed at:
- ISP data centers (China Unicom/China Telecom/China Mobile)
- Major city internet exchange points
- Key transportation hubs
CDN Node Distribution in China:
- Tier-1 cities: Beijing, Shanghai, Guangzhou, Shenzhen
- Tier-2 cities: Hangzhou, Nanjing, Chengdu, Wuhan, Xi'an
- Overseas: Hong Kong, Singapore, Tokyo, Silicon Valley, Frankfurt
Origin Server: The "Main Warehouse" of Content
The origin is where the CDN fetches content from when cache misses occur. It can be:
- Object storage (OSS/COS/S3)
- Self-managed servers (ECS/physical machines)
- Load balancers (SLB/CLB)
Key Configuration:
- Origin HOST: The domain/IP used by CDN nodes when accessing the origin
- Origin Protocol: HTTP or HTTPS
- Origin Port: 80, 443, or a custom port
Mid-Tier Nodes: "Regional Distribution Centers"
Between edge nodes and the origin, CDNs typically have one or more layers of mid-tier nodes:
- Aggregation nodes: Consolidate origin requests from multiple edge nodes to reduce origin pressure
- Regional centers: Responsible for content distribution and scheduling within a large region
Benefits of this layered architecture:
- Reduces origin pressure: 1,000 edge node requests may only require 10 requests to the origin
- Improves hit ratio: Popular content is intercepted at the mid-tier, no need to go back to the origin
- Fault isolation: If one link fails, traffic can automatically switch to another path
2.3 Complete CDN Acceleration Flow
Let's trace a real user request:
Step 1: DNS Resolution (Intelligent Scheduling)
User enters: cdn.example.com/image.jpg
↓
DNS server returns: Beijing Unicom CDN node IP (1.2.3.4)The key here is intelligent DNS: based on the user's ISP, geographic location, and node load, it returns the optimal CDN node IP.
Step 2: Edge Node Lookup (Cache Hit?)
Request arrives at Beijing Unicom CDN node (1.2.3.4)
↓
Node checks local cache:
├─ Hit? Return content directly ✓
└─ Miss? Continue to next stepStep 3: Origin Fetch (Layer by Layer Upward)
Edge node miss
↓
Request to parent node (e.g., North China regional center)
├─ Parent node hit? Return content
└─ Parent node miss? Continue upward
↓
Request to origin
↓
Origin returns contentStep 4: Cache and Return (Faster Next Time)
Content returns along the chain
↓
Each layer caches a copy
↓
Finally reaches the userThis way, the next time a user requests the same file, it can be served directly from the edge node, achieving "instant loading."