Skip to main content
← Back to articles

API Rate Limiting in Production Gateways

Token buckets, per-tenant quotas, and graceful 429 responses that protect shared infrastructure.

Nestlancer Editorial

Share

API Rate Limiting in Production Gateways

Rate limits protect shared infrastructure from noisy neighbors—runaway scripts, scrapers, and buggy client retries that amplify outages.

Algorithm selection

AlgorithmBest for
Token bucketBurst-tolerant APIs
Sliding windowStrict fairness per tenant
Fixed windowSimple public endpoints

Per-tenant limits beat global IP limits for B2B SaaS behind authenticated gateways.

Graceful 429 responses

{
  "error": "RATE_LIMITED",
  "retryAfter": 42,
  "limit": 1000,
  "remaining": 0
}

Include Retry-After header. Clients should backoff with jitter—not hammer the API.

Gateway placement

Enforce at the edge (Kong, Envoy, Cloudflare) before requests hit NestJS pods. Internal service-to-service calls use mTLS identity quotas, not public IP rules.

Exemptions and observability

  • Webhook receivers from trusted partners: higher limits with HMAC verification
  • Admin exports: separate bucket from interactive UI
  • Dashboard: top tenants by 429 count weekly

Rate limiting is product policy encoded in HTTP—document limits in OpenAPI and support responses.

Tenant communication

Publish limit tiers in your developer portal and changelog rate changes 30 days ahead for paid API customers. Sudden 429 spikes after a silent limit change generate support tickets faster than any DDoS.

Comments

Loading comments…

Related posts