Designing Usage Quotas and Stability for LLM Chat on Web and App
This article explains how to design usage quotas and stability controls for LLM chat on web and mobile apps. It covers what quotas measure, how rate-limiting algorithms fit chat workloads, how clients should recover from errors, how to word quota messages, and which metrics to track when launching and tuning limits.
When people use LLM chat on the web or in the mobile app, the most visible questions are usually: “Can I still send a message?”, “Why did I suddenly see ‘try again later’?”, and “Does refreshing or logging in again help?” From an engineering standpoint, a quota should not be a fixed request count hard-coded in the backend. It is a resource allocation policy shaped by identity, device, session, model tier, context length, concurrent connections, feature entry points, and risk level.
Messages such as “This device does not support playback. Try refreshing” show that quota control does not happen only on the server. It also depends on client capabilities, the media playback environment, network quality, and failure recovery paths. If the frontend shows a vague error, users refresh repeatedly, which increases peak load. If the system relies on a single counter, a burst of traffic can crowd out high-value sessions. Quotas, degradation, messaging, and observability therefore need to be designed together.
- Define the quota: what is actually limited
Quotas usually fall into at least four categories. The first is request rate, such as messages per time window, image generations, or file parsing jobs. The second is concurrency, meaning how many inference connections one account or device uses at the same time. The third is budget, which includes input and output tokens, cumulative context length, tool call rounds, and pages parsed from multimedia files. The fourth is fair use, which identifies scripted bulk scraping, shared accounts, and abnormally frequent retries.
Web clients rely more on browser fingerprints, login state, cookies, and IP profiles. Apps can obtain more stable device identifiers, OS versions, and push channels. Neither should treat a single identifier as the final judgment. In practice, a layered identity model works well: the account is the primary key, device and network are supporting signals, and the session is a correction. After login, core quota accumulates per account. Anonymous users get only a small trial quota. Devices under the same account share one budget, which prevents users from bypassing limits by switching clients. Abnormal devices trigger stronger verification only. Normal users are not banned directly.
- Rate limiting should serve the experience, not only precision
Common algorithms each suit different cases. Fixed windows are simple, but they allow double bursts at window boundaries. Sliding windows are smoother and fit message sending frequency. Token buckets allow short bursts, which suits users who ask follow-up questions in quick succession. Leaky buckets enforce steady output and protect inference queues.
A chat product usually combines these approaches. A sliding window at the entry layer curbs spam. A token bucket in the inference scheduler allows interactive bursts. A queue with a concurrency cap handles long tasks such as document parsing or batch summarization. The logic looks like this:
allow = accountBudget.consume(estimatedTokens)and rateLimiter.sliding(userId).allow()and concurrency.acquire(deviceId, modelTier)if !allow:return classifyReason() // rate, budget, concurrency, risk control, or client capability
The key principle is to estimate first and calibrate later. Before a request, estimate conservatively from input length, history context, and expected output. After the response, credit back or debit the budget based on actual usage, so a long output cannot instantly exhaust a user’s quota. For multi-turn sessions, set a context trimming policy. Keep system instructions, recent high-value turns, and summaries, and drop repetitive pleasantries rather than appending history without limit.
- Client differences and error recovery
Web clients are more affected by browser compatibility, suspended tabs, ad blockers, and weak networks. Apps must handle backgrounding, process reclamation, push delivery rates, and local cache consistency.
When users see messages like “Current environment not supported. Please refresh and retry,” the frontend should not push them into refreshing endlessly. It should separate retryable errors from non-retryable ones. Retryable errors include network timeouts, temporary queuing, and interrupted connections. Non-retryable errors include exhausted quota, content policy violations, and missing decoding or rendering capabilities on the device.
For retryable errors, use exponential backoff with jitter, starting at 1s, 2s, and 4s, with an upper limit. When a streaming response is interrupted, resume from the fragments already generated instead of resending the whole turn. Apps can store drafts, attachment hashes, and recent session snapshots locally in encrypted form, then offer “Continue your last answer” after recovery. On the web, duplicate tabs can consume concurrency, so the page can show “Multiple active sessions detected.”
- Quota messages and product tiers
A good message answers three questions: what happened, when service will recover, and what the user can do now. Do not expose internal thresholds or risk control rules, and do not show raw technical error codes. A neutral message might read: “High demand right now. Your request is queued. You can shorten your question, remove attachments, or try again later.” For users approaching their limit, give early warnings. For example, when the remaining budget is low, the interface can say that parsing long documents will use a larger share of the quota.
For product tiers, the basic experience limits model tiers, file size, and history retention. Regular paid use raises context length and concurrency. Team or enterprise scenarios can use a shared pool with a guaranteed allocation for each member, so one member cannot consume the entire budget.
This discussion covers general capabilities only and is not tied to any third-party product. If the system is deployed on Baidu AI Cloud, general product categories such as log services, monitoring and alerting, message queues, and object storage can support auditing, queuing, attachment persistence, and metric dashboards. Availability depends on region. Specific thresholds should still be set by business cost and compliance requirements.
- Observability, gradual rollout, and the cost loop
Before launching a quota policy, establish metrics. Track request success rate, rate-limit hit rate, rejection rate by reason, average queue wait time, time to first token, recovery success rate for interrupted responses, cost per session, share of abnormal devices, and the rate of false-positive complaints. Reports should show whether limits protect the system or drive users away.
Roll out gradually. Start in shadow mode, which records decisions without blocking requests. Then enable enforcement for high-risk actions on a small share of traffic, and finally cover core entry points. Keep a version and a rollback switch for every threshold change.
On cost, focus on three levers: trim wasted context, make long tasks asynchronous, and reuse frequently used system prompts and retrieval results through caching. For compliance, keep necessary audit logs, state how data is used, and collect risk signals with minimal scope.
The goal is to keep limits nearly invisible to normal users, keep the cost of abnormal traffic under control, and make every rejection explainable, actionable, and predictable about when service will recover.
