LLM Rate Limiting: How Inference Capacity Shapes Session Management

    LLM service limits depend not only on request volume but also on the resources each request consumes. This article explains how token throughput, context length, and KV cache usage affect capacity, then examines idle-session eviction, tiered storage, token-bucket rate limiting, and the metrics needed to manage these policies while preserving conversation history.

    Background: Why Service Limits Matter to Engineers

    A weekly financial roundup reported that an LLM service began imposing limits on November 16 because of insufficient compute capacity, no longer supporting long conversations that had been inactive for more than seven days. Although presented as business news, the underlying issue is a capacity-planning problem faced by any online inference service: how to allocate finite resources across growing demand, and how to handle sessions that retain resources over time.

    This article does not assess any particular company or product. Instead, it examines the technical reasons behind such restrictions, the available approaches, and basic implementation patterns for developers building their own services.

    1. Start with the Denominator: Estimating Capacity

    When compute resources become constrained, teams often focus on demand growth without examining how much capacity each request consumes. At its simplest, capacity is a ratio:

    • Numerator: Total available serving capacity, often expressed as generated tokens per second.
    • Denominator: The resources required by an individual request, influenced by input context length, output length, and the required generation speed.

    With a fixed numerator, a larger denominator means fewer concurrent requests. “Starting with the denominator” means understanding per-request resource consumption before deciding whether to scale infrastructure or impose limits.

    The following illustrative code estimates a concurrency ceiling. All values are hypothetical:

    1. def estimate_concurrency(total_tps: float,
    2. avg_output_tokens: float,
    3. target_latency_s: float) -> float:
    4. """
    5. Illustrative estimate of concurrent generation requests.
    6. total_tps: Total cluster output tokens per second
    7. avg_output_tokens: Average output tokens per request
    8. target_latency_s: Target time to complete generation, in seconds
    9. """
    10. per_request_tps = avg_output_tokens / target_latency_s
    11. return total_tps / per_request_tps
    12. # Assume 5,000 output tokens/s, 500 tokens per response,
    13. # and a target completion time of 10 seconds.
    14. print(estimate_concurrency(5000, 500, 10)) # Output: 100.0

    This is a rough estimate, not a complete capacity model. Nevertheless, it illustrates the relationship: longer responses or tighter latency targets reduce the concurrency that the same hardware can sustain. Capacity planning must account for these variables rather than relying on request counts alone.

    2. Why Long Conversations Amplify Resource Costs

    In a multi-turn conversation, the model needs access to the relevant conversation history for each new turn. As that history grows, so does the context that inference must process.

    Common Transformer inference implementations cache attention keys and values in a KV cache, avoiding repeated computation over previously processed context. KV cache memory usage scales roughly with:

    • Context length
    • Number of model layers
    • Number of key/value attention heads and their dimensions
    • Number of sessions in the concurrent batch

    A long conversation whose KV cache remains resident in GPU memory can therefore occupy substantial space even when its user is inactive. As memory usage approaches the system’s limit, these idle cached sessions compete with active requests.

    The cost of a long conversation is therefore not limited to individual inference calls. It can also include retained storage and, when caches remain resident, GPU memory. This is the technical motivation for reclaiming resources associated with inactive sessions.

    3. Strategies for Reclaiming Idle Sessions

    There are three common approaches to handling inactive conversations. The choice depends on the desired user experience and sensitivity to cost.

    Strategy Approach Advantages Trade-offs
    Direct eviction Delete session state after its TTL expires Simple implementation; releases the targeted resources completely If history is deleted as well, users lose it when resuming the conversation
    Tiered storage Keep active session state in GPU memory and move idle state to ordinary storage Preserves history and allows later restoration Adds restoration latency and requires storage-tier management
    Summary compression Replace detailed history with a summary that retains key information Substantially reduces context length and cost May lose details; summary quality must be evaluated

    In practice, these approaches are often combined. For example, after a session becomes idle, a service can persist its full history and release its GPU cache. If the user returns, the service can rebuild the context on demand.

    The following code illustrates the basic structure of idle-session eviction. Persisting history before deletion is the key step:

    1. import time
    2. from dataclasses import dataclass, field
    3. IDLE_TTL_SECONDS = 7 * 24 * 3600 # Example value: 7 days
    4. @dataclass
    5. class Session:
    6. session_id: str
    7. last_active: float = field(default_factory=time.time)
    8. history: list = field(default_factory=list)
    9. class SessionManager:
    10. def __init__(self, idle_ttl: int = IDLE_TTL_SECONDS):
    11. self._sessions: dict[str, Session] = {}
    12. self._idle_ttl = idle_ttl
    13. def get_or_create(self, session_id: str) -> Session:
    14. session = self._sessions.get(session_id)
    15. if session is None:
    16. session = Session(session_id)
    17. self._sessions[session_id] = session
    18. session.last_active = time.time()
    19. return session
    20. def evict_idle(self, archive_fn) -> list[str]:
    21. """Persist history through archive_fn before evicting idle sessions."""
    22. now = time.time()
    23. expired = [
    24. sid for sid, s in self._sessions.items()
    25. if now - s.last_active > self._idle_ttl
    26. ]
    27. for sid in expired:
    28. archive_fn(self._sessions[sid]) # Persist first to avoid data loss
    29. del self._sessions[sid]
    30. return expired

    The archive_fn function can write to object storage or a database, depending on the team’s infrastructure. This example manages application-level session state; it does not implement GPU cache management.

    The guiding principle is to reclaim serving resources without unnecessarily deleting conversation history.

    4. Tiered Rate Limiting: Allocating Finite Capacity

    Reclaiming idle sessions solves only part of the problem. When active requests exceed capacity, the service also needs rate limits to determine which requests are processed, queued, or rejected.

    A common algorithm is the token bucket, which permits short bursts while limiting the long-term average rate. The following implementation can represent quotas measured in requests or tokens:

    1. import time
    2. class TokenBucket:
    3. def __init__(self, rate: float, capacity: float):
    4. self.rate = rate # Tokens replenished per second
    5. self.capacity = capacity # Maximum bucket capacity
    6. self.tokens = capacity
    7. self._updated = time.monotonic()
    8. def allow(self, cost: float = 1.0) -> bool:
    9. now = time.monotonic()
    10. elapsed = now - self._updated
    11. self.tokens = min(self.capacity, self.tokens + elapsed * self.rate)
    12. self._updated = now
    13. if self.tokens >= cost:
    14. self.tokens -= cost
    15. return True
    16. return False

    In a multi-user service, rate limits are commonly organized into tiers:

    • Assign different rate and concurrency limits to different user tiers.
    • Prioritize request types, such as interactive requests over offline batch jobs.
    • Adjust quotas by time period, tightening limits on noncritical work during peak demand.

    Observability is a prerequisite for this design. Without reliable metrics, teams cannot determine which limits need adjustment.

    5. Make Limits Understandable to Users

    Technical restrictions can look like service failures when they are poorly explained. Engineering teams should address the following concerns during design.

    Publish clear, discoverable rules. Document session retention periods, per-request context limits, and concurrency limits. Make relevant information available in documentation or API error responses rather than announcing restrictions only after users encounter them.

    Provide actionable feedback. When a limit is reached, return a clear error code and guidance explaining whether the client should retry, shorten the context, or export the conversation history.

    Give users control over their data. If a conversation is approaching a retention deadline, providing an export or archive option helps users avoid losing important information.

    Separate serving state from user data. GPU-resident caches are computational state that can be released. Conversation records are user data and should be persisted independently. This separation is fundamental to tiered storage.

    6. Engineering Checklist

    When designing or adjusting these policies, review the following areas:

    • Capacity metrics: Cluster output tokens per second, average tokens per request, and queue-time distributions.
    • Session metrics: Active session count, average and maximum context lengths, and the proportion of idle sessions.
    • Cost metrics: Compute cost per thousand tokens, GPU memory utilization, and cache hit rate.
    • Alerting: Notify on-call engineers when queue times exceed thresholds, GPU memory utilization remains elevated, or rejection rates rise sharply.
    • Rollback: Put policy changes behind a switch so the previous rules can be restored quickly, and retain metrics for before-and-after comparisons.

    These metrics are interconnected. A growing share of idle sessions may indicate more reclaimable resources, provided those sessions still retain serving state. A sudden increase in rejections may indicate that per-request consumption—the denominator—has grown beyond expectations.

    Understand that denominator first. Then decide whether to add capacity, adjust rate limits, or change session-management policies.