High-Concurrency Architecture for LLM Applications Under Traffic Spikes
This article examines how to architect large language model (LLM) applications that face sudden marketing-driven traffic surges. It covers capacity planning based on peak load, layered rate limiting at the entry layer, semantic caching and result reuse, asynchronous processing with message queues and idempotency, elastic scaling with the right metrics, and stability safeguards such as circuit breaking and tiered degradation. It also explains how to handle the post-event traffic drop by turning campaign data into reusable knowledge assets and scaling resources back to normal levels.
A sudden traffic spike is not the norm, but your architecture must be designed as if it were. When an LLM application is combined with a burst of marketing traffic, systems often face queuing, timeouts, and throttling, followed by a sharp drop once the campaign ends. This article treats that pattern as a general engineering problem rather than a discussion of any specific product.
1. Abstracting the Problem: Design for the Peak, Optimize for the Normal
Marketing-driven traffic has three typical characteristics. First, it rises steeply: concurrency can grow by one or two orders of magnitude in a short time. Second, it has a long tail: returning visitors and secondary sharing continue after the event ends. Third, it is strongly coupled: a single interaction can trigger recommendations, order placement, payment, and push notifications across multiple service chains. If you scale only for the daily average, queuing, timeouts, and throttling are inevitable at the peak.
The first principle follows directly: use peak load as the baseline for capacity planning and normal load as the baseline for cost optimization, connecting the two through elasticity rather than absorbing everything with a fixed pool of resources.
2. Entry Layer: Stop the Spike at the Outermost Edge
The goal of the entry layer is to reject invalid requests as early as possible, so pressure never reaches expensive inference resources.
- At the access layer, consolidate protocols and reuse connections. For long-lived connections, set reasonable idle timeouts and heartbeat policies to prevent connection buildup from exhausting file descriptors.
- Apply rate limiting in layers: global limits protect the backend, tenant-level limits ensure fairness, and API-level limits protect critical paths. The logic looks like this:
def admit(request):if not global_limiter.allow(): # Global protectionreturn reject(429)if not tenant_limiter.allow(request.tenant): # Fairnessreturn reject(429)if not api_limiter.allow(request.api): # Critical pathreturn queue_or_reject(request)return forward(request)
- Make queuing and degradation explicit: treat “waiting in queue” as a returnable business state instead of leaving users spinning without feedback.
3. Caching and Result Reuse: Eliminate Repeated Computation at the Source
LLM inference is expensive and slow, so caching delivers far more value than it does for conventional read APIs.
- Semantic caching: normalize highly similar questions and serve them from cache. Set a similarity threshold and an expiration policy to avoid irrelevant answers.
- Tiered results: exact matches go to a strongly consistent cache, approximate matches go to the semantic cache, and only cache misses proceed to inference.
- Hotspot pre-warming: before the event starts, preload high-frequency questions, template copy, and campaign rules into the cache to avoid cache penetration at the moment of cold start.
- Three standard safeguards: cache null values to prevent penetration, use mutual exclusion on rebuild to prevent breakdown, and stagger expiration times to prevent a cache avalanche.
4. Asynchronous Processing and Peak Shaving: Trade Queues for Stability
Interactive campaigns generate far more write pressure than read pressure, so writes must be made asynchronous.
- Split “claim reward, increment counter, issue coupon, send notification” into events. Write them to a message queue first, then let consumers process them at a steady rate. System throughput should be determined by consumer concurrency, not entry-layer concurrency.
- Idempotency is a prerequisite for asynchronous processing. Deduplicate using a business unique key:
-- Use campaign ID + user ID + prize batch as the idempotency keyINSERT INTO grant_record (biz_key, user_id, status)VALUES (:biz_key, :user_id, 'INIT')ON CONFLICT (biz_key) DO NOTHING;
- Back eventual consistency with reconciliation: periodically compare grant records against inventory deductions, send discrepancies to a compensation queue for retries, and escalate to manual handling beyond a threshold.
5. Elastic Scaling and Resource Pooling
- Metric selection: do not look at CPU alone. Trigger scaling based on queue backlog length, request queueing time, and inference latency percentiles.
- Scaling speed: keep a portion of always-on buffer capacity to absorb sudden spikes, rely on auto scaling for the rest, and set a scale-out cooldown window to avoid thrashing.
- Resource pooling: containerize the stateless access and business layers and let the container platform schedule them; use object storage for static assets, logging and monitoring services for observability, and a message queue for buffering, forming a general cloud-native combination.
6. Stability Safeguards and Cost Governance
- Circuit breaking and isolation: isolate inference dependencies with thread pools or semaphores so a single slow dependency cannot drag down the whole system.
- Tiered degradation: shut down non-core personalization and recommendations first, while preserving the main interaction and ordering paths.
- Cost guardrails: set a token and call-count budget for each campaign. When the budget is exceeded, automatically switch to a smaller model or template-based replies to avoid “successful traffic, out-of-control bill.”
7. Solving the Post-Event Slump
During the traffic drop-off period, the real problems are retention and normal-load capacity. Anonymize the Q&A data accumulated during the campaign and turn it into knowledge base and cache material, scale elastic resources back to normal specifications, and turn the rate-limiting thresholds validated during the campaign into long-term configuration. Only then does a marketing traffic spike become a sustainable technical asset.
