What to Do When Your LLM Service Is Under a DDoS Attack

    This article explains how to tell a DDoS attack apart from a local problem, why end users have almost no self-help options while an attack is ongoing, and what both users and engineering teams can do about it. It covers immediate user-side tactics such as exponential backoff with jitter, splitting long tasks into resumable chunks, local caching, and switching to asynchronous batch workflows. For developers and enterprises, it walks through multi-provider model routing, circuit breaking and graceful degradation, end-to-end timeout budgets, queue-based peak shaving with backpressure, and observability. It closes with long-term architectural resilience practices and the conclusion that availability has to be designed in rather than waited for.

    What to Do When Your LLM Service Is Under a DDoS Attack

    1. Identify the Symptom: Attack or Your Own Code?

    When an AI coding assistant or an online inference service suddenly stops responding, the first instinct is usually to debug your own code. Under a large-scale traffic attack, however, the failure shows a very consistent set of symptoms:

    • All requests time out uniformly, rather than only specific endpoints failing;
    • The page loads, but chat or inference endpoints hang for a long time and eventually return a gateway-layer error;
    • Success rates stay very low after retries, and latency does not recover naturally over time;
    • The provider’s status page shows degraded service or a maintenance notice.

    If your local network, DNS resolution, and account quota are all fine, and multiple devices across multiple network egresses behave the same way, the problem almost certainly sits on the provider’s side. At that point, tuning parameters, rewriting prompts, or changing client logic will not help, because the bottleneck is not in your process — it is in ingress bandwidth and gateway connection capacity.

    One basic fact needs to be clear: a DDoS (distributed denial-of-service) attack works by exhausting the target’s ingress resources — bandwidth, the connection table, TLS handshake capacity, or the backend thread pool. Attack traffic and legitimate traffic look nearly identical at the protocol layer, so the provider cannot let everything through without sacrificing some legitimate requests. A certain degree of availability loss is therefore unavoidable.

    2. Why Users “Can Only Wait”: Responsibility Boundaries and Resource Reality

    As an end user, you do not control traffic scrubbing appliances, Anycast scheduling, or coordination with upstream carriers. Those belong to the provider’s responsibility. This explains a conclusion that is often misunderstood: while an attack is ongoing, there is almost no effective self-help available on the user side, and waiting for the incident to clear is the rational choice.

    That does not mean doing nothing. The actions that actually matter happen on two levels: reducing your hard dependency on a single online service, and reshaping the interaction pattern from “real-time synchronous” to “tolerant of interruption.”

    3. Immediate Strategies for End Users

    3.1 Back Off, Don’t Retry Aggressively

    Dense retries add pressure exactly when the service is most fragile, and they also get you classified as an anomalous client by rate-limiting policies. Use exponential backoff with random jitter:

    1. import random, time
    2. def call_with_backoff(fn, max_attempts=5, base=1.0, cap=30.0):
    3. for i in range(max_attempts):
    4. try:
    5. return fn()
    6. except Exception:
    7. if i == max_attempts - 1:
    8. raise
    9. delay = min(cap, base * (2 ** i))
    10. time.sleep(delay + random.uniform(0, delay * 0.3))

    3.2 Split Long Tasks and Persist Intermediate Results

    Break one very long context request into several smaller requests, and write intermediate results to a local file or object storage. If a run fails midway during an attack, you only need to re-run the unfinished chunks instead of throwing away the whole round of work.

    3.3 Build Local Caching and Reuse Results

    For requests with strong determinism (same input, same parameters), maintain a local cache key and return immediately on a hit. This saves time and keeps you out of the unavailable window.

    3.4 Change the Interaction Mode

    Convert “must return in real time” scenarios into batch processing: queue locally and submit everything once the service recovers. Most content generation, code completion warm-up, and document summarization tasks can be done asynchronously.

    4. For Developers and Enterprises: Design for Unavailability as the Norm

    4.1 Multi-Provider and Multi-Model Redundancy

    Abstract a unified inference gateway layer that hides the differences between backends and makes model selection configurable:

    1. class ModelRouter:
    2. def __init__(self, providers):
    3. self.providers = providers # ordered by priority
    4. def chat(self, payload):
    5. last_err = None
    6. for p in self.providers:
    7. try:
    8. return p.chat(payload)
    9. except Exception as e:
    10. last_err = e
    11. continue
    12. raise last_err

    The key is a unified interface contract: request and response structures, error semantics, and timeout policies must stay consistent, so that switching is transparent to the business layer above.

    4.2 Circuit Breaking and Graceful Degradation

    Trip the circuit proactively once the error rate crosses a threshold, so threads and connections are not consumed by futile waiting. Degradation policies must be defined in advance: return cached results, fall back to a smaller-parameter model, or serve templated placeholder content — rather than throwing the exception straight at the user.

    1. Error rate > 50% (10s window) → trip circuit for 30s
    2. During the open state → serve cache or fallback copy
    3. Half-open probe → recover if a few trial requests succeed

    4.3 End-to-End Timeout Budget

    Every hop from ingress to the model call needs an explicit timeout ceiling, and the upstream timeout must be larger than the sum of all downstream hops. A missing timeout is the most common “avalanche amplifier.”

    4.4 Queue-Based Peak Shaving and Backpressure

    Introduce a message queue to absorb burst traffic, with consumers pulling at a steady rate that matches their own processing capacity. Queue length and consumption lag should be core monitoring metrics; once they cross a threshold, trigger rate limiting and return an explicit “retry later” semantic upstream.

    4.5 Observability

    Cover at least four categories of data: request volume, success rate, P95/P99 latency, and queue backlog. Pair this with a log service for centralized search, and use monitoring alerts to separate “provider-side failure” from “our own anomaly,” shortening the time spent on misdiagnosis.

    5. Long-Term Protection: Resilience at the Architecture Level

    • Tiered ingress: separate static assets from inference endpoints, with the former served by object storage and a content delivery network, reducing the exposed surface of dynamic entry points.
    • Minimal exposure: do not open direct public access unless necessary, isolate the control plane from the data plane, and keep credentials in a key management service instead of hardcoding them.
    • Capacity headroom: reserve burst capacity and run load tests regularly so you know where the system’s real inflection point is.
    • Drills: inject failures on a schedule to verify that circuit breaking, degradation, and failover actually work. An untested plan is equivalent to no plan.
    • Cost guardrails: set usage limits and alerts so abnormal traffic does not turn into an uncontrollable bill.

    If your business requires high continuity, you can build critical paths on general-purpose capabilities such as Baidu AI Cloud’s container platform, message queue, log service, and monitoring and alerting, gaining baseline burst tolerance through multi-availability-zone deployment and elastic scaling. Concrete specifications and policies should be determined by testing against your own workload rather than copying someone else’s configuration.

    6. Conclusion

    Against a large-scale traffic attack, the right posture for an ordinary user is to recognize the symptoms, stop ineffective retries, switch to asynchronous and cached modes, and wait for the provider to finish scrubbing traffic. What a team genuinely needs to invest in is writing “the online services we depend on may be unavailable at any time” into the design premises: a unified abstraction layer, multi-path redundancy, circuit breaking and degradation, queue-based peak shaving, timeout budgets, and observability. Miss any one of the six and resilience is discounted. Availability is designed, not waited for.