Skip to content

Designing A Content Delivery Network (CDN) – Caching + Edge + Routing

1) Problem Clarification / Làm rõ bài toán

EN

A CDN accelerates delivery of static and dynamic content by placing servers near users.

Content includes:

  • images, videos, CSS/JS
  • web pages
  • API responses
  • streaming content

VI

CDN giúp phân phối nội dung nhanh hơn bằng cách đặt server (edge nodes) gần user.

Nội dung gồm:

  • hình ảnh, video, CSS/JS
  • trang web
  • response API
  • streaming

2) High-Level Goals / Mục tiêu chính

EN

✔ Reduce latency
✔ Reduce origin load
✔ Improve availability
✔ Handle global traffic
✔ Support cache invalidation

VI

✔ giảm latency
✔ giảm tải server gốc
✔ tăng availability
✔ phục vụ traffic toàn cầu
✔ invalidation cache hiệu quả

3) High-Level Architecture / Kiến trúc tổng quan

Client → DNS Routing → Nearest Edge → Cache / Edge Logic → Origin Server

VI

Client → DNS → Edge gần nhất → Cache/Compute → Origin

4) CDN Components / Thành phần CDN

EN

  • Edge cache nodes
  • Regional PoPs (points of presence)
  • Global DNS routing (Anycast/BGP)
  • Origin servers
  • Control plane (purging, rules, config)

VI

  • Edge cache
  • PoP vùng
  • DNS routing
  • Origin server
  • Control plane (purge, rule)

5) Caching Strategies / Chiến lược cache

A) Static Content Caching

EN
Cache images, JS, CSS, PDF with long TTL.

VI
Cache file tĩnh với TTL dài.

B) Dynamic Content Caching

EN
Cache API responses, HTML fragments.

Techniques:

  • Edge-side includes
  • micro-caching (TTL 1–2s)

VI
Cache response API hoặc HTML dynamic.
Dùng micro-cache TTL 1–2s.

C) Cache Hierarchy

EN
Caches layered:

  • Edge cache
  • Regional cache
  • Origin shield
  • Origin

VI
Cache phân tầng:

  • edge
  • regional
  • origin shield
  • origin

6) Routing Strategies

A) DNS-Based Geo Routing

EN
Use GeoDNS to route user to closest PoP.

VI
GeoDNS định tuyến user đến PoP gần nhất.

B) Anycast Routing (industry standard)

EN
All edges share the same IP.
BGP directs users to nearest/healthy node.

VI
Tất cả edge dùng chung 1 IP.
BGP chọn edge gần nhất và khỏe nhất.

C) Load Balancing

EN

  • latency-based
  • health-check based
  • region fallback

VI

  • theo latency
  • theo health
  • fallback region

7) Cache Eviction & TTL Rules

EN

Eviction policies:

  • LRU
  • LFU
  • TTL expiry

Content rules:

  • static: long TTL
  • API: short TTL
  • sensitive: no-cache

VI

Eviction:

  • LRU
  • LFU
  • TTL

TTL theo loại nội dung:

  • static: TTL dài
  • API: TTL ngắn
  • sensitive: no-cache

8) Cache Invalidation

EN

Two models:

A) Purge (explicit invalidation)

Client triggers purge for:

  • product updates
  • price changes
  • breaking news

B) Stale-while-revalidate

Serve stale content while updating cache asynchronously.

VI

A) Purge
Chủ động xóa cache khi cần cập nhật.

B) Stale-while-revalidate
Trả bản cũ trong lúc lấy bản mới.

9) Edge Computing / Logic tại Edge

EN

Modern CDNs (Cloudflare Workers, Akamai EdgeWorkers) allow:

  • auth checks
  • redirects
  • header manipulation
  • bot protection
  • A/B testing
  • API compute at the edge

VI

Edge compute cho phép:

  • xác thực
  • redirect
  • đổi header
  • bảo vệ bot
  • A/B test
  • chạy API tại edge

10) Large File Delivery (Video, Streaming)

EN

Techniques:

  • range requests
  • chunk caching
  • HTTP/3 QUIC transport
  • multi-CDN switching

VI

Mẹo cho file lớn:

  • range request
  • cache theo chunk
  • HTTP/3 QUIC
  • multi-CDN

11) Multi-CDN Architecture

EN

Use multiple CDN providers:

  • Cloudflare
  • Akamai
  • Fastly
  • Amazon CloudFront

Routing via:

  • latency-based
  • availability-based
  • weighted

VI

Dùng nhiều CDN:

  • Cloudflare
  • Akamai
  • Fastly
  • CloudFront

Routing theo latency hoặc availability.

12) Anti-Abuse & Security

EN

  • DDoS protection (L3, L4, L7)
  • Bot mitigation
  • WAF filtering
  • rate limiting at edge
  • TLS termination

VI

  • chống DDoS
  • chặn bot
  • WAF
  • rate limit tại edge
  • TLS termination

13) Observability

EN

Track:

  • cache hit ratio
  • request latency
  • PoP load
  • error rates
  • purge latency

VI

Theo dõi:

  • cache hit
  • latency
  • load PoP
  • lỗi 4xx/5xx
  • thời gian purge

14) Failure Scenarios

EN

  • PoP down → reroute to next closest
  • origin down → serve stale content
  • high load → introduce shielding layer

VI

  • PoP hỏng → route sang PoP khác
  • origin lỗi → trả bản cache cũ
  • quá tải → thêm origin shield

15) Future Enhancements

EN

  • ML-based routing optimization
  • predictive caching
  • edge AI inference
  • real-time log streaming to analytics

VI

  • routing dự đoán bằng ML
  • prefetch thông minh
  • AI tại edge
  • log realtime
Published inSystem Design

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *