CDN (Content Delivery Network) là mạng lưới server phân tán toàn cầu (PoP - Points of Presence). Khi user request file, CDN router tìm server gần nhất về mặt địa lý/network. Lần đầu cache miss: CDN fetch từ origin server và cache lại. Các lần sau: phục vụ từ edge cache — giảm latency đáng kể (từ 200ms còn 20ms) và giảm tải origin. CDN xử lý: static assets (JS/CSS/images), video streaming, software downloads, và ngày nay cả dynamic content qua Edge Functions.
Nên dùng CDN khi: user phân tán toàn cầu, static assets chiếm traffic lớn, cần DDoS protection, media streaming. Không hiệu quả khi: nội dung cực kỳ dynamic/personalized (không cache được), API responses có private data, nội dung thay đổi liên tục với TTL ngắn.
Cache invalidation là thách thức lớn: dùng content hashing (main.abc123.js) để bust cache ngay lập tức khi deploy.
A CDN (Content Delivery Network) is a globally distributed network of servers (Points of Presence, or PoPs). When a user requests a file, the CDN router finds the geographically or network-closest server. On the first cache miss, the CDN fetches from the origin server and caches the response. Subsequent requests are served from the edge cache — significantly reducing latency (e.g., from 200ms to 20ms) and offloading the origin. CDNs handle: static assets (JS/CSS/images), video streaming, software downloads, and increasingly dynamic content via Edge Functions.
Use a CDN when: users are geographically distributed, static assets account for significant traffic, DDoS protection is needed, or for media streaming. CDNs are less effective when: content is highly dynamic or personalized (not cacheable), API responses contain private data, or content changes so frequently that TTLs are very short.
Cache invalidation is a key challenge — use content hashing (e.g., main.abc123.js) to bust the cache immediately on deploy.