System Design Basics for Backend Developers · Ders

Hız Sınırlama ve Kısıtlama

Belirteç kovası ve kayan pencere algoritmaları dahil olmak üzere hız sınırlamanın sistemleri kötüye kullanım ve aşırı yükten nasıl koruduğunu öğrenin.

4. ders / 413 adım

Hız Sınırlama ve Kısıtlama, CoddyKit'te ücretsiz bir System Design Basics for Backend Developers dersidir. Bu, 4 dersinin 4. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, System Design Basics for Backend Developers öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. System Design Basics for Backend Developers kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Why Rate Limit?

Rate limiting caps how many requests a client can make in a time window. It protects a system from abuse, accidental floods, and runaway clients.

  • Stops brute-force and scraping attacks
  • Ensures fair sharing among clients
  • Protects backends from overload

Rate Limiting vs Throttling

The terms overlap but differ slightly: rate limiting rejects requests over a hard cap, while throttling often slows or queues excess requests rather than rejecting them outright.

Fixed Window Counter

The simplest scheme counts requests in fixed time windows, e.g. 100 per minute. It is easy but has an edge problem: a client can send 100 at the end of one window and 100 at the start of the next — 200 in a few seconds.

limit = 100
window = '12:00:00-12:00:59'
count = 0
# reset count to 0 each new window

Sliding Window

A sliding window smooths the edge problem by weighting the previous window or tracking timestamps over a rolling interval. It gives a more accurate, fairer limit at the cost of more bookkeeping.

Token Bucket

The token bucket is the most popular algorithm. Tokens refill at a steady rate up to a capacity. Each request consumes a token; if the bucket is empty, the request is rejected. This allows short bursts while bounding the average rate.

import time
class Bucket:
    def __init__(self, cap, rate):
        self.cap = cap
        self.rate = rate
        self.tokens = cap
        self.last = time.time()
    def allow(self):
        now = time.time()
        self.tokens = min(self.cap, self.tokens + (now - self.last) * self.rate)
        self.last = now
        if self.tokens >= 1:
            self.tokens -= 1
            return True
        return False

b = Bucket(5, 1)
print([b.allow() for _ in range(7)])

Leaky Bucket

The leaky bucket processes requests at a fixed rate, queuing bursts and 'leaking' them out steadily. It smooths traffic into a constant outflow — good when the downstream needs a steady, predictable load.

Choosing the Limit Key

Decide what to limit on:

  • Per API key or user — fair per-account limits
  • Per IP — defends against anonymous abuse
  • Per endpoint — protects expensive operations

Often you combine several keys.

Communicating Limits

Tell clients their status with standard headers and the right status code, so well-behaved clients can back off.

HTTP/1.1 429 Too Many Requests
Retry-After: 30
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1735689600

Distributed Rate Limiting

With many app servers, an in-memory counter per server is inconsistent. Use a shared store like Redis with atomic increments (or Lua scripts) so the limit is enforced globally across the fleet.

INCR rl:user:42
EXPIRE rl:user:42 60
# reject when value > limit

Rate Limiting and DDoS

Rate limiting complements DDoS protection. Application-layer limits stop a single abusive client, while edge and network defenses absorb large volumetric floods before they reach your servers. Defense in depth uses both.

Designing Good Limits

Set limits from real usage data, allow reasonable bursts, expose clear headers, and return 429 with Retry-After. Consider tiered limits — higher caps for paid plans, stricter ones for unauthenticated traffic.

Quick Check

Test your understanding of rate limiting.

Recap

You learned to protect systems with rate limiting:

  • Fixed window, sliding window, token bucket, and leaky bucket
  • Choose limit keys: per user, per IP, per endpoint
  • Return 429 with Retry-After and rate-limit headers
  • Use a shared store like Redis for distributed enforcement
Başlamak ücretsiz

Yapay zeka eğitmeniyle System Design Basics for Backend Developers öğren — ücretsiz

Tarayıcında gerçek kod yaz ve çalıştır, 7/24 yapay zeka eğitmeninden anında yardım al; web'de ya da uygulamada kaldığın yerden devam et.

Kurslar
12
Dersler
48

Sıkça Sorulan Sorular

“Hız Sınırlama ve Kısıtlama” dersi ücretsiz mi?

Evet — “Hız Sınırlama ve Kısıtlama” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve System Design Basics for Backend Developers kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. System Design Basics for Backend Developers kursu toplamda 4 dersten oluşur.

“Hız Sınırlama ve Kısıtlama” dersinde ne öğreneceğim?

Belirteç kovası ve kayan pencere algoritmaları dahil olmak üzere hız sınırlamanın sistemleri kötüye kullanım ve aşırı yükten nasıl koruduğunu öğrenin. System Design Basics for Backend Developers ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

System Design Basics for Backend Developers öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te System Design Basics for Backend Developers, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 4. dersidir.

“Hız Sınırlama ve Kısıtlama” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu System Design Basics for Backend Developers dersinde kod yazıp çalıştırabilir miyim?

Evet. Her System Design Basics for Backend Developers dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Kimlik Doğrulama ve Yetkilendirme
  2. Veri Şifreleme ve Gizlilik
  3. DDoS Koruması ve Güvenlik Duvarları
  4. Hız Sınırlama ve Kısıtlama
← System Design Basics for Backend Developers Sayfasına Dön