API Rate Limiting & Scalability Patterns · บทเรียน

เครือข่ายส่งเนื้อหาและการขยายที่ขอบเครือข่าย

เรียนรู้ว่าเครือข่ายส่งเนื้อหาและการประมวลผลที่ขอบเครือข่ายช่วยลดทราฟฟิกจากต้นทาง ลดเวลาแฝง และรองรับการพุ่งขึ้นของทราฟฟิกด้วยการส่งเนื้อหาจากจุดที่ใกล้ผู้ใช้มากขึ้นได้อย่างไร

บทเรียน 4 จาก 413 ขั้นตอน

เครือข่ายส่งเนื้อหาและการขยายที่ขอบเครือข่าย เป็นบทเรียน API Rate Limiting & Scalability Patterns ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน API Rate Limiting & Scalability Patterns และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส API Rate Limiting & Scalability Patterns มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Moving Work to the Edge

Load balancing, caching, and database scaling all improve the origin. A CDN goes further: it serves responses from servers physically close to the user, before traffic ever reaches your origin.

What a CDN Is

A Content Delivery Network is a global network of edge servers. Users connect to the nearest one (a point of presence), cutting round-trip distance dramatically.

Cache Hits at the Edge

When the edge has a fresh copy of a response, it returns it directly — a cache hit. Your origin never sees the request, which offloads enormous load.

Cache-Control: public, max-age=300
CDN-Cache-Status: HIT

Cache-Control Directives

You tell the CDN how to cache via headers:

  • max-age — seconds the response stays fresh
  • s-maxage — overrides max-age for shared caches like CDNs
  • private — never cache at the edge

Caching Dynamic API Responses

Even API JSON can be cached if it is the same for many users. Use short TTLs and vary the cache key by query string or auth scope to keep responses correct.

Cache-Control: public, s-maxage=30
Vary: Accept-Encoding

Cache Invalidation

Stale data is the hard part. Strategies:

  • TTL expiry — let it age out
  • Purge — explicitly evict a URL after a write
  • Versioned URLs — change the path so the old one is irrelevant

Absorbing Traffic Spikes

During a flash of traffic, a CDN serves cached responses to most users so the origin sees only a trickle. This is a key defense against both viral spikes and certain DDoS patterns.

Edge Compute

Modern CDNs run code at the edge — edge functions. You can do auth checks, A/B routing, or response shaping near the user without a trip to the origin, shaving latency further.

export default async (request) => {
  if (!request.headers.get('Authorization'))
    return new Response('Unauthorized', { status: 401 });
  return fetch(request);
};

Origin Shielding

A designated shield POP sits between all edges and your origin. Cache misses funnel through it, so the origin is hit at most once per object rather than once per region.

Measuring CDN Effectiveness

Track the cache hit ratio — the fraction of requests served from the edge. A high ratio means low origin load and fast responses. Low ratios point to poor caching headers or highly personalized content.

Stale-While-Revalidate

The stale-while-revalidate directive lets the edge serve a slightly stale response instantly while it fetches a fresh copy in the background. Users never wait on the origin, and content stays current.

Cache-Control: max-age=60, stale-while-revalidate=300

Quick Check

Test your CDN knowledge.

Recap

You learned how the edge scales APIs:

  • CDNs serve responses from nearby POPs
  • Cache-Control headers govern freshness
  • Invalidation via TTL, purge, or versioning
  • Edge compute and origin shielding cut origin load further
เริ่มต้นได้ฟรี

เรียนรู้ API Rate Limiting & Scalability Patterns ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
12
บทเรียน
48

คำถามที่พบบ่อย

บทเรียน “เครือข่ายส่งเนื้อหาและการขยายที่ขอบเครือข่าย” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “เครือข่ายส่งเนื้อหาและการขยายที่ขอบเครือข่าย” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส API Rate Limiting & Scalability Patterns ให้อัปเกรดเป็น CoddyKit PRO คอร์ส API Rate Limiting & Scalability Patterns มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “เครือข่ายส่งเนื้อหาและการขยายที่ขอบเครือข่าย”

เรียนรู้ว่าเครือข่ายส่งเนื้อหาและการประมวลผลที่ขอบเครือข่ายช่วยลดทราฟฟิกจากต้นทาง ลดเวลาแฝง และรองรับการพุ่งขึ้นของทราฟฟิกด้วยการส่งเนื้อหาจากจุดที่ใกล้ผู้ใช้มากขึ้นได้อย่างไร คุณปฏิบัติ API Rate Limiting & Scalability Patterns ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน API Rate Limiting & Scalability Patterns หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน API Rate Limiting & Scalability Patterns บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “เครือข่ายส่งเนื้อหาและการขยายที่ขอบเครือข่าย” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน API Rate Limiting & Scalability Patterns นี้ได้ไหม

ได้ บทเรียน API Rate Limiting & Scalability Patterns ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. เทคนิคการกระจายภาระงาน
  2. กลยุทธ์การแคชที่มีประสิทธิภาพ
  3. พื้นฐานสำคัญของการขยายขนาดฐานข้อมูล
  4. เครือข่ายส่งเนื้อหาและการขยายที่ขอบเครือข่าย
← กลับไปที่ API Rate Limiting & Scalability Patterns