What to Do When Your LLM API Is Under a DDoS Attack
This article explains why online LLM services suddenly become unavailable during distributed denial-of-service (DDoS) attacks, how to tell an upstream outage apart from a bug in your own code, and what both individual users and engineering teams can do about it. It covers retryable error classification, exponential backoff with jitter, circuit breaking and bulkhead isolation, queue-based asynchronous calls, multi-provider failover, semantic caching, graceful degradation, observability and capacity planning, plus basic edge protection for self-hosted inference entry points and a post-incident review checklist.
1. Why LLM Services Suddenly Become Unavailable
Many users calling hosted LLM APIs eventually run into requests that hang for a long time, responses that come back rate limited, queue positions that never advance, or endpoints that are simply unreachable. In most cases this does not mean the model has become “dumber” or has stopped working. It means availability at the service entry layer is being degraded by external traffic. The typical explanation from the provider is that it is under a distributed denial-of-service (DDoS) attack, and that ordinary users can only wait for mitigation.
That conclusion is honest, but it is far too passive for engineering practice. We can break “waiting” down into problems that engineering effort can actually mitigate: entry bandwidth and connection counts being exhausted, backlogs piling up at the auth and gateway layers, backend inference capacity being squeezed out, and rate-limiting policies tightening on their own. Understanding these layers is what lets you design a business system that stays usable while an upstream dependency is down.
The essence of a DDoS attack is exhausting one scarce resource in the target system using a large volume of requests from many distributed sources. For an online inference service, that scarce resource might be entry bandwidth, TLS handshake capacity, concurrent gateway connections, auth quota, or GPU inference slots. The attacker does not need to “guess” the model correctly. They only need to make the entry layer unable to absorb legitimate traffic.
2. How to Tell an Upstream Failure From Your Own Code
Before changing anything, do an accurate layered diagnosis so you don’t mistake upstream instability for a local defect.
- Look at the distribution of error types. A simultaneous rise in connection timeouts, handshake failures, gateway-level 5xx responses, and rate-limit messages usually points to the entry layer. Errors concentrated in parameter validation and parsing failures more likely mean your client code is calling the API incorrectly.
- Look at time correlation. Several unrelated workloads degrading in the same time window is a strong signal of an external dependency failure.
- Look at single-point reproduction. If the failure persists from a different network and a different machine, you can largely rule out a local network problem.
- Look at response headers and error-code semantics. Rate-limit errors usually carry explicit retry semantics and should be treated as “retryable” rather than “permanently failed.”
A sketch of the decision logic looks like this:
RETRYABLE = {"timeout", "unavailable", "rate_limited", "gateway_error"}def classify(err):if err.code in RETRYABLE:return "retry" # Upstream entry-layer instability, safe to retry with backoffif err.code in {"invalid_request", "auth_failed"}:return "fix_local" # Local calling problem, retrying is pointlessreturn "fallback" # Unknown error, take the degradation path
3. What Individual Users Should Do
For individual users without control over the infrastructure, the goal is not to “fix the service” but to avoid wasting time on actions that accomplish nothing.
- Don’t refresh or resubmit at high frequency during the attack window. It adds to entry congestion and can get you classified as abnormal traffic.
- Use low-frequency probing plus backoff: retry at progressively longer intervals, and return to your normal pace as soon as a request succeeds.
- Split long tasks into pieces. Breaking one very long context request into several short rounds significantly reduces the rework cost of any single failure.
- Keep drafts locally. Persist prompts, intermediate results, and completed fragments on your machine so you don’t have to start from zero after recovery.
- Follow the provider’s official announcement channels and treat authoritative information as the source of truth, so you aren’t misled by unverified claims.
4. Architecture-Level Mitigations for Developers and Enterprises
What actually determines business continuity is whether the calling architecture assumes the upstream may be unavailable at any time.
1. Timeouts, Retries, and Exponential Backoff With Jitter
Retries must be paired with backoff and jitter, otherwise they create a synchronized second wave of load.
import random, timedef call_with_backoff(fn, max_attempts=5, base=0.5, cap=8.0):for i in range(max_attempts):try:return fn()except Exception as e:if classify(e) != "retry" or i == max_attempts - 1:raisesleep = min(cap, base * (2 ** i)) * (0.5 + random.random())time.sleep(sleep)
Three points matter: set a total budget instead of retrying forever; apply backoff only to retryable errors; and use random jitter to spread out concurrency peaks.
2. Circuit Breaking and Bulkhead Isolation
Trip the circuit when the failure rate crosses a threshold: fail fast and enter the degradation branch, so threads, connections, and memory aren’t drained by slow requests. At the same time, split independent connection pools and quotas per business line (the bulkhead pattern) so one non-critical scenario can’t consume the entire quota.
3. Queueing and Asynchronous Processing
Turn synchronous calls into “enqueue, consume asynchronously, deliver results via callback or polling.” A message queue smooths out peaks and valleys, letting you replay the backlog at a controlled rate once the upstream recovers instead of firing off an instant flood.
4. Multi-Provider and Multi-Channel Redundancy
Where compliance and cost allow, integrate two or more inference channels and route and fail over between them through a unified abstraction layer. That layer should hide the differences between providers and expose only a common “text generation / embedding” semantic interface.
Client -> Gateway (auth / rate limiting / routing)|--> Provider A (primary)|--> Provider B (secondary, failover)|--> Local Small Model (fallback)
5. Caching and Result Reuse
Apply semantic caching to requests that are largely deterministic. A cache hit returns immediately, which cuts cost and provides natural resistance to attack. The cache key should include a hash of the model identifier, the parameters, and the normalized prompt.
6. Graceful Degradation
During the attack window, degrade in stages: disable non-core polishing and long-form capabilities and keep only core question answering; use a smaller local model to return results that are usable but simplified; and where necessary return a templated response while clearly telling the user that the system is in a degraded state.
7. Observability and Capacity Planning
Track four core metrics — entry success rate, P95 latency, rate-limit ratio, and token consumption rate — and configure tiered alerts. Run failure drills regularly to verify that circuit-breaker thresholds, queue backlog limits, and scale-out scripts actually work. If the workload runs in the cloud, you can combine general capabilities such as container-platform autoscaling, load balancing, monitoring and alerting, and logging services to enable automatic scaling and fast diagnosis.
5. Basic Protection for Self-Hosted Inference Entry Points
Teams that control the infrastructure should put protection at the entry point rather than at the model layer: scrub abnormal traffic at the edge, apply rate limiting layered by source and identity, cap long-lived connections and oversized request bodies, enable connection reuse and handshake caching to lower connection setup cost, and reject unauthenticated requests as early as possible. The core principle is “the earlier you reject, the more resources you save” — keep invalid traffic in front of expensive resources, not behind them.
6. Post-Incident Review Checklist
- Were all failed requests during the attack window correctly identified as retryable, or were any misclassified as business failures?
- Did circuit breaking and degradation trigger as expected, and was the backlog replay smooth after recovery?
- What was the cache hit rate, and how much did the user-visible failure rate change during degradation?
- Were the scale-out steps in the capacity plan ever actually executed?
- Was external communication timely and consistent in its messaging?
7. Conclusion
When an upstream service is under a DDoS attack, individual users genuinely have little direct influence and can only wait for mitigation. Engineering teams, however, can compress the impact of that uncontrollable window into an acceptable range. Combine retry backoff, circuit breaking and isolation, queue-based peak shaving, multi-channel redundancy, cache reuse, and graceful degradation into a coherent system, backed by solid observability and drill practices, and your service will stay basically available through upstream instability and return smoothly to normal levels once it recovers.
