LONG AI 如何在不增加上游容量下將閘道 429 回應率由 15.98% 降至 2.74%
How we cut our gateway's 429 rate from 15.98% to 2.74% without buying more capacity
LONG AI 將自身閘道的 429 回應率由 15.98% 降至 2.74%,期間沒有增加上游容量。團隊為每個上游模型組合設置獨立佇列,按可用容量派發請求,並在拒絕前採用背壓和重新路由。11 天內,p95 延遲由 1.4 秒升至 1.6 秒,平均每次請求成本則下降。
We serve a few hundred client applications through one OpenAI-compatible endpoint, aggregating 51 upstream sellers. Our worst problem was never a model being unavailable; it was the gateway answering 429 Too Many Requests to customers who had done nothing wrong.
On 2026-11-09, 15.98 percent of all requests through the gateway returned 429. That number is not a capacity error in the usual sense: aggregate upstream capacity was fine. It was an admission control failure, and fixing it took three changes, none of which required buying more quota.
What was actually happening
Each request landed in a queue that was ordered by arrival time. Upstream rate limits are not uniform: one seller allows 200 requests per minute on a model, another allows 20. A request routed to the slow seller sat in front of requests routed to the fast one, so the fast upstream idled while its queue grew behind a single slow call. When the queue grew past a fixed depth, the gateway rejected the request outright with 429.
Three separate faults stacked:
- One global queue instead of one per upstream-model pair.
- Arrival-order dispatch instead of dispatch by available capacity.
- Fail-fast at a fixed queue depth instead of back-pressure and re-routing.
The three changes
Per-upstream queues. Every upstream-model pair got its own queue and its own concurrency budget, seeded from the limit the seller publishes. The global queue disappeared, and with it the head-of-line blocking.
Dispatch by capacity, not by arrival. A request is sent to the fastest upstream-model pair that currently has budget, subject to a per-customer weight so one integration cannot starve others. This is where most of the improvement came from: we were previously leaving the cheap upstream idle while the expensive one was saturated.
Back-pressure before rejection. When an upstream queue exceeds 70 percent of its budget, new requests are routed elsewhere rather than rejected. Only when every eligible upstream is above threshold does the gateway queue the request briefly, and only if that brief queue would exceed the client's own timeout do we return 429.
The result
- 429 rate: 15.98 percent → 2.74 percent in eleven days, with no additional upstream capacity purchased.
- p95 latency rose from 1.4 seconds to 1.6 seconds — the price of waiting instead of failing.
- Average cost per request fell, because the router stopped sending work to the expensive channel whenever the cheap one had headroom.
The rule we now apply when evaluating an upstream seller: ask for its published per-model concurrency and requests-per-minute limits, not a vague "high concurrency" claim. A gateway that queues for 300 milliseconds is worth more than one that answers 429 in 20 milliseconds.
If you are evaluating a marketplace, check whether failed and retried requests are billed, and whether the queue behaviour is documented rather than discovered: https://ai.dijinlong.com/faq
The gateway's API documentation, including how limits and retries are surfaced to clients: https://ai.dijinlong.com/docs
Per-model upstream and concurrency data is listed here: https://ai.dijinlong.com/model-plaza
And the cost side, including how routing affects the final invoice: https://ai.dijinlong.com/pricing
Disclosure: I run LONG AI, the gateway described above. The numbers are from our own traffic between 2026-11-09 and 2026-11-20.
來源:DEV Community · dev.to