0Pricing
Indie Hacker Mobile Apps · درس

تحديد معدل طلبات API واستراتيجيات التخزين المؤقت

احموا الواجهة الخلفية وخفّضوا التكاليف عبر تطبيق تحديد معدل الطلبات لإيقاف إساءة الاستخدام، وطبقات التخزين المؤقت التي تقلل العمل المكرر وتسرّع الاستجابات.

تحديد معدل طلبات API واستراتيجيات التخزين المؤقت درس مجاني في Indie Hacker Mobile Apps على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 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.

الأسئلة الشائعة

هل درس «تحديد معدل طلبات API واستراتيجيات التخزين المؤقت» مجاني؟

نعم — نص درس «تحديد معدل طلبات API واستراتيجيات التخزين المؤقت» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Indie Hacker Mobile Apps، انتقل إلى CoddyKit PRO. تتضمن دورة Indie Hacker Mobile Apps 4 دروس في المجموع.

ماذا ستتعلم في «تحديد معدل طلبات API واستراتيجيات التخزين المؤقت»؟

احموا الواجهة الخلفية وخفّضوا التكاليف عبر تطبيق تحديد معدل الطلبات لإيقاف إساءة الاستخدام، وطبقات التخزين المؤقت التي تقلل العمل المكرر وتسرّع الاستجابات. تتمرن على Indie Hacker Mobile Apps مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Indie Hacker Mobile Apps؟

لا تُشترط خبرة سابقة. Indie Hacker Mobile Apps على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «تحديد معدل طلبات API واستراتيجيات التخزين المؤقت»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Indie Hacker Mobile Apps هذا؟

نعم. كل درس في Indie Hacker Mobile Apps يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. تحسين أداء BaaS
  2. عمليات دمج الواجهة الخلفية المخصصة
  3. أفضل ممارسات أمان التطبيقات المحمولة
  4. تحديد معدل طلبات API واستراتيجيات التخزين المؤقت
← العودة إلى Indie Hacker Mobile Apps