เชฎเซเช–เซเชฏ เชธเชพเชฎเช—เซเชฐเซ€ เชชเชฐ เชœเชพเช“
JobCannon
เชฌเชงเชพ เช•เซŒเชถเชฒเซเชฏเซ‹

API Rate Limiting

Protecting APIs from abuse while ensuring fair access

โฌข เชŸเชฟเชฏเชฐ 3เชŸเซ‡เช•เชจเชฟเช•เชฒ
+$10k-
เชชเช—เชพเชฐ เชชเชฐ เช…เชธเชฐ
4 เชฎเชนเชฟเชจเชพ
เชถเซ€เช–เชตเชพเชจเซ‹ เชธเชฎเชฏ
เชฎเชงเซเชฏเชฎ
เชฎเซเชถเซเช•เซ‡เชฒเซ€
4
เช•เชฐเชฟเชฏเชฐ
เชเช• เชจเชœเชฐเชฎเชพเช‚

API rate limiting controls request volume per client using token bucket, sliding window, or fixed window algorithms. Distributed implementations via Redis handle multi-server environments. Understanding rate limit headers (RateLimit-* vs X-RateLimit-*), per-user/IP/key strategies, and retry-after semantics is essential for backend systems. Career path: Practitioner (fixed window, basic HTTP 429, $95-125k) โ†’ Architect (distributed token bucket, multi-tier limits, $140-190k) โ†’ Expert (adaptive limits, quota billing integration, $180-260k).

API Rate Limiting เชถเซเช‚ เช›เซ‡

API rate limiting controls how many requests clients can make within a time window, protecting services from abuse, DDoS attacks, and noisy neighbors. Implementing effective rate limiting requires understanding token bucket, sliding window, and fixed window algorithms, along with distributed rate limiting in multi-server environments. This is a critical system design skill tested in senior engineering interviews and essential for anyone building public APIs or multi-tenant platforms.

๐Ÿ”ง เชŸเซ‚เชฒเซเชธ เช…เชจเซ‡ เช‡เช•เซ‹เชธเชฟเชธเซเชŸเชฎ
RedisUpstashCloudflare Rate LimitingAWS API Gateway throttlingKongEnvoyTykBottleneckLua scripts in RedisNGINX limit_reqNode.js rate-limiter-flexibleExpress rate-limit

๐Ÿ“‹ เชคเชฎเซ‡ เชถเชฐเซ‚ เช•เชฐเซ‹ เชคเซ‡ เชชเชนเซ‡เชฒเชพเช‚

๐Ÿ’ฐ เชชเซเชฐเชฆเซ‡เชถ เชชเซเชฐเชฎเชพเชฃเซ‡ เชชเช—เชพเชฐ

เชชเซเชฐเชฆเซ‡เชถเชœเซเชจเชฟเชฏเชฐเชฎเชงเซเชฏเชฎเชธเชฟเชจเชฟเชฏเชฐ
USA$110k$155k$210k
UKยฃ65kยฃ95kยฃ135k
EUโ‚ฌ72kโ‚ฌ105kโ‚ฌ145k
CANADAC$118kC$165kC$225k

๐ŸŽฏ API Rate Limiting เชจเซ‹ เช‰เชชเชฏเซ‹เช— เช•เชฐเชคเซ€ เช•เชฐเชฟเชฏเชฐ

โš– เชธเชพเชฅเซ‡ เชธเชฐเช–เชพเชฎเชฃเซ€ เช•เชฐเซ‹

โ“ FAQ

Token bucket vs sliding window vs fixed window, which one should I use?
Fixed window: simplest, per-minute counters, prone to edge-case bursts at window boundary. Token bucket: smooth refill at constant rate, handles bursts gracefully, industry standard for public APIs (GitHub, Stripe use it). Sliding window: accurate but complex, higher memory cost in distributed systems. Default to token bucket for new APIs; fixed window only for simple internal services.
How do I implement distributed rate limiting across multiple servers?
Single-server rate limiting (in-memory counters) fails immediately when you scale. Use Redis as the source of truth: each request increments a counter with TTL = window size. Lua scripts atomically check-and-increment to avoid race conditions. For geo-distributed systems (multi-region), replicate Redis across regions or accept slightly stale limits for performance.
What headers should I return: RateLimit-* or X-RateLimit-*?
IETF standard is RateLimit-Limit / RateLimit-Remaining / RateLimit-Reset (RFC 6585). GitHub uses X-RateLimit-* (legacy de-facto standard, still widely recognized). Return both for compatibility: RateLimit-* for modern clients, X-RateLimit-* for legacy. Always include Retry-After header with 429 responses (seconds or HTTP-date format).
Per-user, per-IP, or per-API-key rate limiting, how do I choose?
Per-user (for authenticated requests): fairest, prevents account abuse. Per-IP (for public/unauthenticated endpoints): blocks abusers but punishes office-behind-NAT. Per-API-key: best for B2B APIs, allows tiered limits per subscription. Combine all three: strictest limit applies. Example: 1000/day per user, 100/min per IP, 10k/day per API key.
How do I handle rate limiting with exponential backoff on the client side?
Check Retry-After header (in seconds or HTTP-date). Implement exponential backoff: wait 2^attempt seconds (1, 2, 4, 8, 16โ€ฆ) with jitter (ยฑ20%) to avoid thundering herd. For 429 responses, obey Retry-After strictly. For other transient failures (5xx), backoff is optional. Libraries: `axios-retry` (Node.js), `tenacity` (Python), `@shopify/network` (TypeScript).
Free tier vs paid tier rate limiting, how do I differentiate?
Embed tier in the request context (user object or API key lookup). Apply loose limits to free tier (100 req/min), tight to premium (1000 req/min). Use same algorithm for both; just parameterize the limit. Track limit exhaustion per tier for analytics/billing. Offer burst allowance to premium tiers (smooth out spikes).
Should I return 429 Conflict or 503 Unavailable when rate limited?
Use HTTP 429 Too Many Requests (RFC 6585) for client-side rate limit hits. Use 503 Service Unavailable only for server overload (not the client's fault). 429 signals 'retry later' (idempotent), while 503 suggests 'backend is down' (may not be safe to retry). Always pair 429 with Retry-After header.

เช–เชพเชคเชฐเซ€ เชจเชฅเซ€ เช•เซ‡ เช† เช•เซŒเชถเชฒเซเชฏ เชคเชฎเชพเชฐเชพ เชฎเชพเชŸเซ‡ เช›เซ‡?

เช•เชฐเชฟเชฏเชฐ เชฎเซ‡เชš เชŸเซ‡เชธเซเชŸ เช†เชชเซ‹ โ€” เช…เชฎเซ‡ เชฏเซ‹เช—เซเชฏ เชŸเซเชฐเซ‡เช•เซเชธ เชธเซ‚เชšเชตเซ€เชถเซเช‚.

เชฎเชพเชฐเชพ เชถเซเชฐเซ‡เชทเซเช -เชซเชฟเชŸ เช•เซŒเชถเชฒเซเชฏเซ‹ เชถเซ‹เชงเซ‹ โ†’

เชคเชฎเชพเชฐเซ‹ เช†เชฆเชฐเซเชถ เช•เชฐเชฟเชฏเชฐ เชชเชพเชฅ เชถเซ‹เชงเซ‹

2,521 เช•เชพเชฐเช•เชฟเชฐเซเชฆเซ€เช“เชฎเชพเช‚ เช•เซŒเชถเชฒเซเชฏ-เช†เชงเชพเชฐเชฟเชค เชฎเซ‡เชšเชฟเช‚เช—. เชฎเชซเชค.

เช•เชฐเชฟเชฏเชฐ เชฎเซ‡เชš เชŸเซ‡เชธเซเชŸ เช†เชชเซ‹ โ€” เชฎเชซเชค โ†’