AI Inference Cost and Capacity Governance After Traffic Spikes
This article presents a practical framework for keeping large language model inference stable and cost-efficient under uneven traffic pulses, using the post-holiday analysis of major AI campaigns as context. It covers traffic profiling, a four-part breakdown of per-call cost, tiered model routing, caching and reuse, queueing, rate limiting and graceful degradation, observability metrics, and post-event reviews that turn a one-off campaign into reusable capacity, cost and quality models.
During the holiday period, several major internet platforms competed aggressively for traffic around AI-powered interactive features. According to public reports, one platform spent roughly 3 billion RMB on marketing and channel sponsorships across four TV galas, drawing 130 million users into AI interactions to claim rewards; the system became overloaded at peak and order requests were throttled. Another spent about 1 billion RMB on red-envelope referral campaigns, and one platform recorded interactions in the range of 1.9 billion in a single day. Once the noise fades, the real engineering work begins: keeping inference services stable under both predictable and unpredictable traffic pulses while pushing the cost per call into a sustainable range. This article takes a neutral perspective and lays out a complete practical framework.
1. What a Traffic Pulse Really Is: Not High QPS, but Highly Uneven Distribution
Holiday-style campaigns share three traffic characteristics: clearly defined start and end times, highly concentrated entry points, and extreme variation in the value of individual requests. This means capacity planning based on average daily QPS will be badly distorted. A more sound approach is to build a traffic profile first, then discuss scaling.
- Time dimension: separate the warm-up, peak, and long-tail phases, and set an SLO for each.
- Entry dimension: identify conversion differences across sources such as the campaign page, share-driven returns, and push notifications.
- Request dimension: distinguish short chat-style requests from long document-summarization requests; their compute costs can differ by an order of magnitude.
Illustrative profiling logic:
# Illustrative only: aggregate per minute, output peak ratio and long-request sharefrom collections import defaultdictdef profile(records):per_min = defaultdict(lambda: {"count": 0, "long": 0})for ts, tokens in records:bucket = per_min[ts // 60]bucket["count"] += 1if tokens > 2000:bucket["long"] += 1peak = max(v["count"] for v in per_min.values())avg = sum(v["count"] for v in per_min.values()) / len(per_min)return {"peak_ratio": peak / avg,"long_ratio": sum(v["long"] for v in per_min.values()) / len(records)}
The peak ratio is typically far above rule-of-thumb values, and the long-request share determines the pressure on GPU memory and queueing latency. These two metrics are the basis for every decision that follows.
2. Cost Governance: Breaking a Single Call into Four Optimizable Stages
The cost of LLM inference is not determined by call volume alone. It can be split into four stages and optimized separately.
- Input preprocessing cost: redundant context, repeated system prompts, and overly long conversation history. The countermeasures are prompt templating and history trimming, keeping only the turns relevant to the current intent.
- Prefill cost: roughly linear in input length. The countermeasure is prefix reuse, placing fixed system instructions and knowledge snippets in a cacheable prefix position.
- Decode cost: strongly correlated with output length. The countermeasures are output length caps and structured output to reduce redundant wording.
- Failed-retry cost: retries triggered by timeouts and rate limiting are often overlooked. Exponential backoff and idempotency keys are essential to avoid retry storms.
# Illustrative only: call wrapper with idempotency key and backoffdef call_with_backoff(client, payload, idem_key, max_retry=3):for i in range(max_retry):try:return client.chat(payload, idempotency_key=idem_key)except RateLimited:sleep(2 ** i + random.random())raise RuntimeError("exceeded retry budget")
3. Tiered Model Routing: Meeting Intent with the Minimum Necessary Compute
Not every request needs the largest model. A three-tier routing scheme works well: intent recognition and formatting go to a small model; routine Q&A goes to a mid-sized model; only complex reasoning and long-document analysis are escalated to a large model. Routing decisions should be based on quantifiable signals rather than manual intuition.
if input length < 512 and intent in {chitchat, lookup, extraction}:route -> lightweight modelelif multi-step reasoning required or input length > 4000:route -> high-capability modelelse:route -> standard model
A quality regression set is also required: run an offline evaluation every time routing thresholds change, to prevent cost reductions from being accompanied by a quality collapse.
4. Caching and Reuse: Hit Rate Is the Most Direct Cost Lever
Stacking semantic caching, prefix caching, and result caching can typically cut repeated computation significantly. The key implementation point is that cache keys must include the model version, prompt version, and key parameters; otherwise you get incidents where “the prompt changed but an old result was still served.”
- Semantic caching: match synonymous phrasings via vector nearest-neighbor search, with a similarity threshold and a human fallback.
- Prefix caching: place fixed instructions first to improve batching efficiency.
- Result caching: set a short TTL for deterministic lookup-style requests.
5. Elasticity and Stability: Queueing, Rate Limiting, and Degradation
Under pulse traffic, scaling speed is always slower than the rate of traffic growth, so queueing and protection mechanisms are mandatory. It is advisable to introduce a message queue for peak shaving, converting synchronous calls into asynchronous tasks with results pushed back; to apply tiered rate limiting at the gateway layer, prioritizing paid or high-value paths; and to prepare degradation strategies, such as disabling non-core polishing and rewriting capabilities while keeping only the main Q&A.
For observability, at least four categories of metrics should be covered: request volume and latency percentiles (P50/P95/P99), token consumption and cache hit rate, failure and retry rates, and cost per request. Logging and monitoring/alerting should be connected so that drill-downs by campaign dimension are possible.
6. Post-Event Review: Turning One Campaign into a Long-Term Capability
The end of a campaign is not the end of the work. Three deliverables are recommended: first, a capacity baseline that writes the peak ratio into the next planning cycle; second, a cost dashboard that aggregates cost per call by business line; third, a quality regression report confirming that cost reduction did not hurt the experience. If an organization wants to reduce the operational burden of running its own inference clusters, it can consider using container platforms on Baidu AI Cloud to host elastic inference, object storage to hold evaluation datasets, and a message queue for traffic shaping, with a unified monitoring and alerting system for observability, so that effort stays focused on the business and its outcomes.
In summary, a traffic flood is only a stress test. The real dividing line is whether reusable capacity, cost, and quality models have been established. With all three in place, the next pulse can arrive without relying on ad hoc scaling and manual firefighting.
