Home » Content Delivery Network: CDN Architecture, Edge Computing, Caching Strategies และ Performance
Content Delivery Network: CDN Architecture, Edge Computing, Caching Strategies และ Performance
Content Delivery Network: CDN Architecture, Edge Computing, Caching Strategies และ Performance
Content Delivery Network (CDN) กระจาย content ไปยัง edge servers ทั่วโลกเพื่อให้ users เข้าถึงได้เร็วขึ้น CDN Architecture ประกอบด้วย origin server, edge PoPs และ caching layers, Edge Computing ประมวลผลที่ edge ใกล้ users, Caching Strategies กำหนดว่า content ไหนจะ cache นานแค่ไหน และ Performance optimization ลด latency และเพิ่ม throughput สำหรับ web applications
ถ้าไม่มี CDN ทุก request ต้องเดินทางไป origin server ที่อาจอยู่อีกฝั่งโลก: user ในไทยเข้า website ที่ host ใน US → 200-300ms latency per request ถ้าหน้า web มี 50 resources = รอหลายวินาที CDN ให้ content ถูก serve จาก edge server ที่ใกล้ user ที่สุด → latency ลดเหลือ 10-50ms
CDN Architecture
| Component |
Role |
Location |
| Origin Server |
Source of truth — เก็บ original content ทั้งหมด |
Data center (1-2 locations) |
| Edge Server (PoP) |
Cache copies ของ content → serve users directly |
กระจายทั่วโลก (100-300+ locations) |
| Mid-Tier Cache |
Regional cache ระหว่าง edge กับ origin (ลด origin load) |
Regional data centers |
| DNS/Anycast |
Route users ไป nearest edge server |
Global DNS infrastructure |
| Control Plane |
Manage cache rules, purge, configuration, analytics |
CDN provider dashboard/API |
CDN Request Flow
| Step |
Action |
| 1. DNS Resolution |
User request → DNS resolve ไป CDN edge (Anycast routing → nearest PoP) |
| 2. Cache Hit |
Edge server มี content ใน cache → serve ทันที (fastest) |
| 3. Cache Miss |
Edge ไม่มี → request ไป mid-tier cache หรือ origin → cache → serve |
| 4. Cache Fill |
Response จาก origin ถูก cache ที่ edge → future requests = cache hit |
| 5. TTL Expiry |
Cache หมดอายุ → revalidate กับ origin (If-Modified-Since / ETag) |
Edge Computing
| Feature |
รายละเอียด |
| คืออะไร |
Run code ที่ CDN edge (ไม่ใช่แค่ cache static content — compute at edge) |
| Cloudflare Workers |
JavaScript/WASM ที่ run บน 300+ edge locations (V8 isolates) |
| AWS CloudFront Functions |
Lightweight functions ที่ CDN edge (viewer request/response manipulation) |
| Lambda@Edge |
AWS Lambda functions ที่ CloudFront regional edge caches |
| Vercel Edge Functions |
Edge runtime สำหรับ Next.js applications |
| Deno Deploy |
Globally distributed JavaScript/TypeScript runtime |
| Use Cases |
A/B testing, auth, geolocation redirect, image optimization, API gateway at edge |
Caching Strategies
| Strategy |
How |
Best For |
| Cache-Control: max-age |
Cache สำหรับ N seconds (e.g., max-age=3600 = 1 hour) |
Static assets (CSS, JS, images) |
| Cache-Control: s-maxage |
CDN-specific max-age (override max-age สำหรับ shared caches) |
CDN caching ที่ต่างจาก browser caching |
| Cache-Control: no-cache |
Cache ได้ แต่ต้อง revalidate กับ origin ทุกครั้ง |
Dynamic content ที่อาจเปลี่ยน |
| Cache-Control: no-store |
ห้าม cache เลย (sensitive data) |
Personal data, banking, auth pages |
| stale-while-revalidate |
Serve stale content → revalidate ใน background |
Content ที่ freshness ไม่ critical (news, blog) |
| ETag / Last-Modified |
Conditional request → 304 Not Modified ถ้ายังไม่เปลี่ยน |
ลด bandwidth (ไม่ต้อง transfer body ถ้าไม่เปลี่ยน) |
| Cache Key |
กำหนดว่า cache key ประกอบด้วยอะไร (URL, headers, cookies, query strings) |
Vary caching ตาม device, language, user type |
CDN Providers
| Provider |
PoPs |
จุดเด่น |
| Cloudflare |
300+ |
Largest edge network, free tier, Workers (edge compute), DDoS protection |
| AWS CloudFront |
400+ |
AWS integration, Lambda@Edge, S3 origin, pay-per-use |
| Akamai |
4,000+ |
Largest CDN (enterprise), media delivery, security |
| Fastly |
80+ |
Real-time purge, VCL (Varnish Config), edge compute (Compute@Edge) |
| Google Cloud CDN |
140+ |
GCP integration, Anycast, Media CDN for streaming |
| Azure CDN |
130+ |
Azure integration, multiple CDN providers (Microsoft, Akamai, Verizon) |
Performance Optimization
| Technique |
Improvement |
| Image Optimization |
Auto-convert to WebP/AVIF, resize, compress → 50-80% smaller |
| Minification |
Minify CSS/JS/HTML → remove whitespace/comments → 20-40% smaller |
| Brotli Compression |
Brotli (br) compression → 15-25% better than gzip |
| HTTP/2 + HTTP/3 |
Multiplexing, header compression, 0-RTT (QUIC) → faster page loads |
| Prefetch/Preload |
Prefetch resources ก่อน user click → perceived zero latency |
| Early Hints (103) |
Server send hints ก่อน full response → browser start loading resources earlier |
| Cache Hit Ratio |
Target > 90% cache hit ratio → ลด origin load + faster responses |
ทิ้งท้าย: CDN = Bring Content Closer to Users
Content Delivery Network Architecture: origin → mid-tier cache → edge PoPs (100-300+ locations) → users Flow: DNS → nearest edge → cache hit (fast) or miss (fetch origin → cache → serve) Edge Computing: run code at edge (Cloudflare Workers, Lambda@Edge, Vercel Edge) Caching: max-age (static), s-maxage (CDN), stale-while-revalidate, ETag (conditional) Providers: Cloudflare (free tier, 300+ PoPs), AWS CloudFront, Akamai (largest), Fastly Performance: image optimization, Brotli, HTTP/3, prefetch, > 90% cache hit ratio Key: CDN reduces latency from 200-300ms to 10-50ms — essential for modern web performance
อ่านเพิ่มเติมเกี่ยวกับ Load Balancing L4 vs L7 HAProxy Nginx และ DDoS Protection Mitigation Strategies ที่ siamlancard.com หรือจาก icafeforex.com และ siam2r.com