Token Rate Limits, Quotas and Backpressure
By the Katkat team · Updated · 9 min read
Quick overview
Learn how provider token limits, token buckets, bounded queues, per-tenant fairness and graceful degradation keep an LLM app stable under load.
After this lesson you should be able to explain why LLM APIs limit tokens as well as requests, and how a token bucket models that limit. You should also be able to describe how queues, per-tenant fairness and a degradation ladder stop one traffic spike from taking down the whole product. Interviewers use this topic to check whether you treat model calls as a scarce, metered resource rather than a free function call.
What provider limits actually measure
Hosted model providers usually enforce several limits at once. Names and exact rules differ by vendor and plan, so check the documentation, but the common shapes are:
- Requests per minute (RPM): protects the provider from many tiny calls.
- Tokens per minute (TPM): protects GPU capacity. Often input and output tokens are counted, sometimes with different weights.
- Concurrent requests: a cap on in-flight calls.
- Daily or monthly quotas and spend caps: budget controls, usually tied to your account tier.
When you exceed a limit, the provider typically returns HTTP 429 (Too Many Requests), and often a Retry-After header or limit headers saying when to try again. Overload on the provider's side (5xx or "overloaded" errors) is a different failure and should be handled separately from your own quota.
The key subtlety is that you do not know a request's cost in advance. Input tokens you can count with the model's tokenizer (see Tokenization). Output tokens are unknown until generation ends. Some providers estimate usage at admission time using the max_tokens you set, so a generous max_tokens can use up your limit even when responses are short. Verify how your provider counts this.
Self-hosted serving has the same problem with different units: your "limit" is GPU throughput and KV cache memory (see Serving LLMs), and the same patterns apply.
Token buckets: the core mechanism
A token bucket is the standard way to enforce a rate while allowing short bursts. (Do not confuse bucket "tokens" with LLM tokens. For an LLM limiter, one bucket unit happens to equal one LLM token.)
- The bucket has a capacity (the largest burst allowed).
- It refills at a constant rate (the sustained limit).
- Each request must take its cost from the bucket. If there is not enough, it waits or is rejected.
For an LLM client you typically run two buckets, one for requests and one for tokens, and a call proceeds only when both can pay.
Because true cost is unknown at admission, use reserve then reconcile:
- Estimate cost = input tokens + a reserved output allowance.
- Deduct the estimate from the bucket.
- When the response finishes, compute the actual cost and refund the difference.
Worked example
Suppose your provider allows 400,000 TPM and 2,000 RPM. Your average request has 1,500 input tokens, and you set max_tokens to 1,000. Real outputs average 300 tokens.
| Strategy | Cost per request | Requests per minute by TPM |
|---|---|---|
| Reserve full max_tokens, never refund | 1,500 + 1,000 = 2,500 | 400,000 / 2,500 = 160 |
| Reserve, then refund unused | 1,500 + 300 = 1,800 effective | 400,000 / 1,800 ≈ 222 |
Refill rate is 400,000 / 60 ≈ 6,667 tokens per second. The RPM limit (2,000) is not the bottleneck here; TPM is. Reserving without refunding wastes about 28% of capacity (160 versus 222, so 160/222 ≈ 0.72). Lowering max_tokens to a realistic ceiling, say 500, gives a reservation of 2,000 and 200 requests per minute, with no extra machinery. Note that if the provider itself counts max_tokens against your limit, your own refunds only help your internal accounting, so tuning max_tokens is the real lever.
Setting bucket capacity below the full minute's allowance (for example, 10 seconds' worth, about 66,700 tokens) smooths bursts so you do not spend the whole minute's budget in the first second and then stall.
Queueing and backpressure
When demand exceeds the refill rate, requests must go somewhere. The choices are wait, drop, or push the problem back to the caller.
Backpressure means making overload visible to upstream components instead of absorbing it silently. An unbounded queue hides overload: latency grows without limit, memory grows, and by the time a user's request reaches the model they may have given up, so you pay for an answer nobody reads.
Use a bounded queue sized from the latency you can tolerate. Capacity per queue = service rate × maximum acceptable wait. With the earlier numbers, service rate is 160 requests per minute ≈ 2.67 per second. If the product tolerates 10 seconds of queueing, the queue should hold about 2.67 × 10 ≈ 27 requests. If arrivals run at 240 per minute (4 per second), the excess is 80 per minute, so a 27-slot queue fills in roughly 20 seconds (27 / 1.33 per second). After that you must reject or degrade, and the rejection should be fast and explicit.
Related ideas:
- Admission control: decide at the door whether a request can be served within its deadline. Reject early rather than fail late.
- Deadlines: attach a timeout to each request, and drop queued items whose deadline has passed.
- Priorities: interactive chat should jump ahead of batch jobs such as nightly summarisation. Batch work can use a separate, lower-priority bucket or run only when the main bucket has spare tokens.
- Little's law: in-flight requests = arrival rate × time in system. At 2.67 requests per second and 8 seconds per call, about 21 requests are in flight. Use this to set concurrency limits and worker counts.
- Cancellation: if a user disconnects from a streamed response, cancel the upstream call. Otherwise you keep paying for tokens and holding quota (see Streaming and Latency Metrics).
Queue time counts toward the latency users feel, including time to first token, so monitor it as its own metric.
Retries without making things worse
A 429 is a signal to slow down, not to hammer. Good client behaviour:
- Honour
Retry-Afterwhen present. - Otherwise use exponential backoff with jitter: wait a random time between 0 and min(cap, base × 2^attempt). With base 1 s and cap 30 s, the third retry waits a random time up to 8 seconds. Jitter prevents many clients from retrying in lockstep.
- Use a retry budget, for example retries may add at most 10% to total traffic. Without one, a total outage with 3 retries per call multiplies load by 4, which is a retry storm.
- Retry only retryable errors. A 400 for a malformed request will never succeed.
- Make retries safe: for calls with side effects, such as tool calls inside an agent, use idempotency (see Making Agents Reliable).
The best retry is the one you avoid: the proactive token bucket should keep you under the limit so 429s are rare, and the reactive backoff is the safety net.
Per-tenant fairness
In a multi-tenant product, one shared provider limit is a shared resource. Without controls, one customer running a bulk import can starve everyone else (the noisy neighbour problem).
Common approaches:
| Approach | How it works | Trade-off |
|---|---|---|
| Hard per-tenant quota | Each tenant gets a fixed bucket (e.g. 1/N of the total) | Simple and predictable, but wastes capacity when others are idle |
| Max-min fair sharing | Split capacity evenly; unused share goes to heavier tenants | Efficient, more complex to implement |
| Weighted fair queueing | Shares proportional to plan tier or contract | Matches pricing, needs weight management |
| Global bucket plus per-tenant caps | Everyone draws from the shared bucket, each capped | Easy; fairness only at the cap |
Worked example
Capacity is 160 requests per minute across three tenants. Tenant A demands 300, B demands 40, C demands 40. An equal split gives 53.3 each, which wastes capacity: B and C only need 40. Max-min fairness gives B and C their full 40 each, and A receives the rest: 160 − 80 = 80. Total used is 160, and no tenant that is under its fair share is starved.
Practical details: keep per-tenant buckets in a shared store such as Redis if you run multiple app instances, and tag every request with tenant ID so observability can show who is consuming what. Let tenants see their usage and limits, and return a clear 429 with a retry hint to your own API clients, so your backpressure propagates outward.
Graceful degradation
When capacity is short, the question becomes what to give up first. Define a degradation ladder in advance, ordered from least to most visible to the user:
| Step | Action | Cost to the user |
|---|---|---|
| 1 | Serve from a semantic cache for repeated questions | Almost none |
| 2 | Lower max_tokens or ask for shorter answers | Shorter responses |
| 3 | Trim retrieved context or history (see Context Windows) | Possibly less accurate |
| 4 | Route to a smaller or cheaper model, or a second provider (see Model Routing and Fallbacks) | Lower quality |
| 5 | Defer non-urgent work to an asynchronous batch queue | Delayed result |
| 6 | Reject with a clear message and a retry time | Request fails |
Rules for a good ladder: trigger steps from measured signals (queue depth, 429 rate, remaining budget) rather than guesses; degrade the low-priority and free-tier traffic first; and tell users when quality is reduced if it matters (for example, "using a faster mode"). Test the ladder with load tests or fault injection, because degradation paths that never run in testing tend to be broken when you need them.
Quality changes from fallbacks need evaluation too: a smaller model that passes your evals for FAQ traffic may fail on complex requests, which is why routing rules should be informed by LLM evals.
How does this come up in interviews?
1. Your LLM feature starts returning 429s at peak. What do you do?
First confirm which limit is hit (RPM, TPM, concurrency) from the response headers and logs. Then add a client-side token bucket so you stay under the limit proactively, lower max_tokens to a realistic value, and add backoff with jitter and a retry budget for the remaining 429s. Longer term, request a higher tier, add a fallback provider, and cache repeated requests.
2. How would you design rate limiting for a multi-tenant LLM API? Count tokens, not just requests, using reserve-then-reconcile because output length is unknown. Give each tenant a bucket based on plan, share spare capacity using max-min or weighted fairness, and keep state in a shared store. Expose usage and return clear 429 responses with retry hints.
3. Why is an unbounded queue in front of an LLM a bad idea? Under sustained overload, wait time grows without limit, so users time out while the system still spends tokens on abandoned requests. A bounded queue sized as service rate × tolerable wait, plus deadlines and fast rejection, keeps latency predictable. It also makes overload visible so upstream systems can slow down.
4. What does graceful degradation look like for an LLM product? Define an ordered ladder: cache, shorter outputs, trimmed context, cheaper model or fallback provider, deferred batch, then explicit rejection. Trigger each step from queue depth or error rate, and degrade low-priority tenants first. Evaluate the degraded modes so you know their quality in advance.
5. How do retries make an outage worse, and how do you prevent that?
If every failed call is retried several times, offered load multiplies (3 retries means up to 4 times the traffic) just when the system is struggling. Synchronised retries also arrive in waves. Prevent it with exponential backoff, jitter, a retry budget, honouring Retry-After, and circuit breakers that stop calling a failing dependency for a short period.
Common mistakes
- Limiting by request count only, when the provider limit is on tokens.
- Setting
max_tokensvery high "just in case", which inflates reserved cost and can throttle you at a fraction of real usage. - Using an unbounded queue, so overload shows up as slow, then failed, then expensive.
- Retrying immediately or without jitter, and retrying non-retryable errors.
- Keeping per-tenant limits in one process's memory when the app runs on many instances.
- Letting batch jobs and interactive traffic share one priority level.
- Continuing generation after the client has disconnected.
- Building fallbacks that were never tested or evaluated for quality.
- Treating a 429 (your quota) and a 5xx or overload response (provider trouble) as the same problem.