Rate Limiting and GPU Scheduling for LLM Serving: A Practical Guide

    This guide explains why large language model (LLM) inference services face GPU supply-demand imbalance as usage grows, and how rate limiting and compute scheduling help. It covers KV Cache memory usage, session lifecycle management, input length limits, quotas, concurrency isolation, and peak-off-peak pricing, along with client-side retry and degradation strategies, capacity testing, and observability practices for building resilient LLM applications under limited compute.

    1. Background: Compute Supply-Demand Imbalance Under Surging Call Volume

    The load profile of large language model (LLM) inference services differs significantly from that of traditional online services. The cost of a traditional request is roughly proportional to the number of input and output bytes, whereas LLM inference cost is amplified by three factors at once: context length, the number of concurrent sessions, and the number of generation steps. As the user base grows quickly, compute demand does not rise linearly; the effects stack and multiply. On the supply side, accelerator cards and GPU memory capacity become hard constraints.

    The industry commonly responds along three paths: scaling out, scheduling, and constraint. Scaling out takes a long time and is expensive. Scheduling and constraint can take effect within hours, which makes them the first choice in the short term. A platform’s recent decision to lower limits for regular users is a typical example of the third path.

    2. Core Mechanism: The Relationship Between Long Sessions and Cache Usage

    To understand limit policies, you first need to understand the key-value cache (KV Cache) in autoregressive generation. As the model generates token by token, it keeps the key and value tensors computed at the attention layers for historical tokens resident in GPU memory, avoiding recomputing the prefix at every step. Its memory usage can be approximated as:

    1. CacheBytes ≈ 2 × layers × kvHeads × headDim × seqLen × batch × dtypeBytes

    Here, 2 accounts for the two tensors, keys and values. As you can see, usage is proportional to sequence length. A continuously growing conversation can keep occupying scarce GPU memory with its cache or session state, even if no one interacts with it for a long time, as long as the session is still considered “resumable.” This creates the “zombie session” problem.

    Therefore, reclaiming sessions that have been idle beyond a certain duration with no active interaction is essentially taking GPU memory back from low-value occupants and reallocating it to active requests. Two common constraints usually come with this: a per-request input length cap (for example, on the order of tens of thousands of tokens) and a daily conversation quota. The three controls manage the “single-request peak,” “per-session accumulation,” and “per-user total” respectively, forming a complete load-shaping toolkit.

    3. Availability Perspective: Degradation and Outage Are Not the Same Thing

    Service anomalies need to be understood in tiers. Common levels include:

    • Performance degradation: slower responses, higher time to first token, and occasional request failures, but requests can still be submitted overall;
    • Partial outage: one type of entry point or one model capability is unavailable while other paths work normally;
    • Complete outage: all entry points fail.

    From an engineering perspective, the first two are the norm. Availability metrics are usually measured by the share of successful requests, for example around 99.5% monthly availability, which translates to tens of hours of unavailable windows over a year. This suggests that architecture design must assume “dependencies will degrade,” not “dependencies are always available.”

    4. A Checklist of Common Levers

    1. Session lifecycle governance: set an idle-reclaim threshold; expired sessions must rebuild context;
    2. Input length constraints: cap per-request context, and prompt users to trim history when necessary;
    3. Quotas and allowances: set token buckets by user, by day, and by API;
    4. Peak-off-peak pricing: off-peak prices lower than peak prices to shift traffic away from peaks;
    5. Concurrency isolation: set independent concurrency caps for different capabilities or specs to prevent them from crowding each other out;
    6. Priority queues: paid or critical workloads go first; low-priority tasks can queue or be rejected.

    Illustrative token bucket and concurrency isolation logic:

    1. class TokenBucket:
    2. def __init__(self, rate, capacity):
    3. self.rate, self.capacity = rate, capacity
    4. self.tokens, self.ts = capacity, time.monotonic()
    5. def allow(self, need=1):
    6. now = time.monotonic()
    7. self.tokens = min(self.capacity, self.tokens + (now - self.ts) * self.rate)
    8. self.ts = now
    9. if self.tokens >= need:
    10. self.tokens -= need
    11. return True
    12. return False
    13. # Use independent rate limiters and concurrency semaphores for different capabilities to achieve fault isolation
    14. limiters = {"flash": TokenBucket(60, 120), "pro": TokenBucket(10, 20)}

    5. Recommendations for Developers

    • Slim down context: keep only necessary history, and summarize long documents before sending them as input;
    • Persist sessions: write conversation state to external storage and rebuild it at the application layer after expiry, instead of relying on server-side resumption;
    • Elastic retries: use exponential backoff for degradation-type errors to avoid retry storms;
    • Off-peak scheduling: run batch and offline jobs during off-peak hours to take advantage of time-based pricing;
    • Observability: instrument time to first token, failure rate, and quota-hit counts separately, and configure monitoring and alerts;
    • Graceful degradation: switch to a smaller model or cached results when the primary model is unavailable.

    6. Capacity Evaluation and Load Testing Methods

    Before launch, run three types of validation: first, long-session load testing to observe how GPU memory and latency change with sequence length; second, peak-concurrency load testing to confirm that rate limit thresholds and queueing policies behave as expected; third, failure drills that inject latency and errors to verify the degradation paths. For metrics, look at throughput, time to first token, end-to-end latency, and the share of each error category at the same time, rather than averages alone.

    7. Conclusion

    Rate limiting is not a step back in capability; it is a means of resource pricing and scheduling under compute scarcity. Only by understanding the mechanics of cache usage, quotas, concurrency isolation, and time-based pricing can you design resilient applications when service fluctuates. With common cloud capabilities such as container platforms, message queues, object storage, and monitoring and alerting, teams can put these strategies into engineering practice and achieve predictable service quality with limited compute.