API Rate Limiting in Production Gateways
Token buckets, per-tenant quotas, and graceful 429 responses that protect shared infrastructure.
Nestlancer Editorial

Rate limits protect shared infrastructure from noisy neighbors—runaway scripts, scrapers, and buggy client retries that amplify outages.
Algorithm selection
| Algorithm | Best for |
|---|---|
| Token bucket | Burst-tolerant APIs |
| Sliding window | Strict fairness per tenant |
| Fixed window | Simple 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

Case Studies
Cutting Deploy Time from 45 Minutes to Five
CI caching, smaller artifacts, and service-level pipelines after monolith split.

Case Studies
Scaling a Freelance Marketplace Architecture
Matching algorithms, escrow flows, and dispute resolution at growing GMV.

Case Studies
GDPR Compliance Platform Rebuild
Data maps, deletion workflows, and consent logging across microservices.

Case Studies
Migrating from WebSockets to SSE
Simpler infra, CDN friendliness, and trade-offs for one-way realtime feeds.