By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
A rate limit is not a punishment for a noisy client; it is how the service stays predictable for everyone. Model capacity is a shared, expensive, external resource with hard concurrency limits and long tails. When demand exceeds capacity, the system must decide who waits, who degrades and who is told to come back later — explicitly, before the queue grows without bound.
The first control is a per-tenant limit, because one carrier running a bulk recompute should not starve the exception desk. The second is a global limit at the provider boundary. The third is a queue with a bound and a deadline: work that cannot start within its budget should never be enqueued.
from dataclasses import dataclass
@dataclass
class WindowLimiter:
"""Fixed-window per-tenant limiter.
Simple and predictable for teaching. Production often uses a token
bucket or sliding window so a burst at a window edge cannot pass twice.
"""
limit: int = 3
window_ms: int = 60_000
started_ms: int = 0
used: int = 0
def allow(self, now_ms: int) -> tuple[bool, int]:
if now_ms - self.started_ms >= self.window_ms:
self.started_ms = now_ms
self.used = 0
if self.used < self.limit:
self.used += 1
return True, 0
retry_after_ms = self.started_ms + self.window_ms - now_ms
return False, retry_after_ms
limiter = WindowLimiter()
for offset in (0, 1000, 2000, 3000):
allowed, retry_after_ms = limiter.allow(offset)
print(f"t={offset}ms allowed={allowed} retry_after_ms={retry_after_ms}")| Control | Scope | Default for Waypoint | On breach |
|---|---|---|---|
| Request rate | Per tenant and route | 60 requests/minute, burst 10 | 429 with Retry-After and a structured body |
| Concurrent model calls | Per feature | 32 in flight | Queue if wait < 500 ms, else shed |
| Provider concurrency | Global | Provider quota minus safety margin | Queue with a deadline, then fall back |
| Queue depth | Per feature | 50 items or one second of wait | Reject new work with 429 or 503 |
| Spend budget | Per tenant per day | Configured per contract | budget_exceeded with a reset time |
| Prompt size | Per request | Context limit with headroom | Reject before enqueue; never truncate silently |
Key takeaways
Rate limits protect shared model capacity and keep one tenant from starving another.
Limit per tenant and per route, bound provider concurrency, and cap queue depth and wait.
Return 429 with Retry-After and a structured body; never let queues grow without bound.
Shed load in order: malformed work, low-priority tiers, cheaper alias, honest error.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.