0Pricing
Indie Hacker Mobile Apps · บทเรียน

การจำกัดอัตราและกลยุทธ์แคชชิงของส่วนเชื่อมต่อโปรแกรมประยุกต์

ปกป้องระบบหลังบ้านและลดต้นทุนด้วยการใช้การจำกัดอัตราเพื่อหยุดการใช้งานในทางที่ผิด และใช้ชั้นแคชเพื่อลดงานซ้ำซ้อนและเร่งการตอบสนอง

การจำกัดอัตราและกลยุทธ์แคชชิงของส่วนเชื่อมต่อโปรแกรมประยุกต์ เป็นบทเรียน Indie Hacker Mobile Apps ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Indie Hacker Mobile Apps และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Indie Hacker Mobile Apps มีบทเรียนทั้งหมด 4 บทเรียน

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

Why Limit and Cache

As your app grows, two problems appear: abusive or runaway clients hammering your API, and the same expensive work repeated needlessly. Rate limiting and caching solve both.

Together they protect uptime and slash costs.

What Is Rate Limiting?

Rate limiting caps how many requests a client can make in a window — for example 100 requests per minute. Beyond that, requests are rejected or delayed.

It defends against abuse, bugs, and accidental loops.

The Token Bucket

A common algorithm is the token bucket: each request consumes a token; tokens refill at a steady rate. When the bucket is empty, requests are throttled.

let tokens = 5;
function allowRequest() {
  if (tokens > 0) { tokens--; return true; }
  return false;
}
console.log(allowRequest());
console.log(allowRequest());

Communicating Limits

Good APIs return headers like X-RateLimit-Remaining and a 429 Too Many Requests status with a Retry-After hint.

This lets well-behaved clients back off gracefully.

What Is Caching?

Caching stores the result of expensive work so repeat requests return instantly without recomputing or re-fetching.

A cache hit saves database load, compute, and time.

Cache Keys and TTL

Each cached entry has a key identifying the request and a TTL (time to live) after which it expires and is refreshed.

const cache = new Map();
function setCache(key, value, ttlMs) {
  cache.set(key, { value, expires: Date.now() + ttlMs });
}
setCache('user:1', { name: 'Alice' }, 60000);
console.log(cache.get('user:1'));

Cache Layers

Caching happens at multiple levels:

  • Client: in-app cache
  • CDN: at the edge near users
  • Server: in-memory or Redis

Each layer cuts work from the one below it.

Cache Invalidation

The hard part: stale data. When the underlying data changes, the cache must be invalidated or it serves outdated results.

Strategies include short TTLs, event-based invalidation, and versioned keys.

What Not to Cache

Avoid caching:

  • Highly personalized or sensitive data without scoping by user
  • Rapidly changing values where staleness misleads

Cache what is read often and changes rarely.

Combining the Two

Rate limiting and caching reinforce each other. Caching reduces how often you hit the limit, and limits protect uncached, expensive endpoints from abuse.

Apply both per endpoint based on cost and sensitivity.

A Protection Checklist

Before scaling:

  • Rate limit per user and per IP
  • Return 429 with Retry-After
  • Cache hot, slow-changing reads with sensible TTLs
  • Plan invalidation up front
  • Never cache sensitive data unscoped

Resilient and cheap to run.

Quick Check

Test your rate limiting and caching knowledge.

Recap

You learned to protect and speed up your backend:

  • Rate limiting caps requests and defends against abuse
  • Token bucket is a common algorithm; return 429 with Retry-After
  • Caching stores expensive results across client, CDN, and server
  • Use TTLs and plan invalidation to avoid stale data
  • Combine both per endpoint by cost and sensitivity

Resilient, fast, and cheap to operate.

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

บทเรียน “การจำกัดอัตราและกลยุทธ์แคชชิงของส่วนเชื่อมต่อโปรแกรมประยุกต์” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การจำกัดอัตราและกลยุทธ์แคชชิงของส่วนเชื่อมต่อโปรแกรมประยุกต์” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Indie Hacker Mobile Apps ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Indie Hacker Mobile Apps มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การจำกัดอัตราและกลยุทธ์แคชชิงของส่วนเชื่อมต่อโปรแกรมประยุกต์”

ปกป้องระบบหลังบ้านและลดต้นทุนด้วยการใช้การจำกัดอัตราเพื่อหยุดการใช้งานในทางที่ผิด และใช้ชั้นแคชเพื่อลดงานซ้ำซ้อนและเร่งการตอบสนอง คุณปฏิบัติ Indie Hacker Mobile Apps ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Indie Hacker Mobile Apps หรือไม่

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

บทเรียน “การจำกัดอัตราและกลยุทธ์แคชชิงของส่วนเชื่อมต่อโปรแกรมประยุกต์” ใช้เวลานานแค่ไหน

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

ฉันเขียนและรันโค้ดในบทเรียน Indie Hacker Mobile Apps นี้ได้ไหม

ได้ บทเรียน Indie Hacker Mobile Apps ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

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

  1. การเพิ่มประสิทธิภาพ BaaS
  2. การเชื่อมต่อระบบส่วนหลังแบบกำหนดเอง
  3. แนวทางปฏิบัติที่ดีที่สุดด้านความปลอดภัยของแอปมือถือ
  4. การจำกัดอัตราและกลยุทธ์แคชชิงของส่วนเชื่อมต่อโปรแกรมประยุกต์
← กลับไปที่ Indie Hacker Mobile Apps