Design a Usage-Limit Notice for a Mobile AI Chat App
Design the API response and the Android client behavior that tell a chat user they have hit a model's usage limit, when they can try again, and how to upgrade, in their own language.
Problem statement
Design a usage-limit feature for an AI chat app on Android. When a user sends a message and has already reached the usage limit, the API response must tell the app that the limit was reached and give it everything it needs to explain this.
The app shows the error in a snackbar that says the model has reached its usage limit, includes a link to upgrade to a paid plan, and says when the user can try again (for example, in X hours). The app supports many languages.
Explain how the server knows the limit has been reached, what the API returns, how the snackbar behaves when the user sends two messages in quick succession, and how a Jetpack Compose screen triggers the snackbar.
For this exercise, assume each plan allows a fixed number of messages per model in a rolling five-hour window, for example 40 messages for the most capable model on the free plan. A send that would go over the limit is rejected before the model runs and does not count.
A user may be signed in on several devices at once; while the counting store is healthy, concurrent sends from those devices must never take the total over the limit. What a send does when the counting store is unavailable (let it through for a while, or reject it) is a trade-off for you to choose and justify.
The paid plan has higher limits, and a user already on the highest plan sees no upgrade link. Payments and the upgrade purchase flow, the model itself, the choice of limit numbers, and iOS and web clients are outside scope.
What to build
- When a user sends a message to a model whose limit they have already reached in the current window, the message is not processed or counted, and the app receives a structured usage-limit response.
- The app shows a snackbar saying the model has reached its usage limit, when the user can try again, and an upgrade link when the user's plan can be upgraded.
- The notice appears in the user's app language with correct plural forms for the wait time, including right-to-left languages.
- Sending twice in quick succession, or retrying after a lost response, neither counts a message twice nor stacks duplicate snackbars.
At scale
- For this exercise, assume 20 million daily active users, each with usage state for each model they use, and peaks of 100,000 message sends per second; the limit check may add at most 20 milliseconds at p99 to a send.
- For this exercise, assume a user can send from up to five signed-in devices at once, and while the counting store is healthy the combined count must never go over the plan's limit in any window.
- For this exercise, assume the app supports 30 languages, including right-to-left languages and languages with more than two plural forms, and app versions up to six months old must still show a sensible notice when the server adds a new kind of limit.