Katkat

Design Mobile Model Usage Quotas

OpenAIAndroid Engineer · Technical Screen

Last updated

Design an end-to-end quota and rate-limiting system for a mobile AI chat client, focusing on client-side state management, API contract design, and multi-device synchronization.

Scenario

You are an Android engineer building the model usage tiering and quota system for a mobile AI assistant app (e.g., ChatGPT). The system limits users on advanced models (e.g., 40 messages every 3 hours for Pro users, or 10 requests per day on Free tiers). When a user nears or hits their limit, the UI must react smoothly—displaying remaining allowances, countdown timers to quota reset, and upgrade or wait prompts without degrading message latency.

Requirements

Functional Requirements

  • Client UX & State: Surface remaining quota and an accurate countdown timer for quota reset. Disable or adapt the send action when the limit is reached.
  • Error & Edge Handling: Handle mid-stream quota exhaustion, rapid consecutive submissions, and out-of-sync multi-device usage.
  • Atomic & Consistent Enforcement: Ensure the server remains the authoritative source of truth, while allowing the client to provide an optimistic, responsive UI.

Non-Functional Requirements

  • Latency: Quota checking should not add round-trip overhead before dispatching a message.
  • Reliability: Gracefully handle clock drift on the client and transient network failures.
  • Scale: 50 million daily active users (DAU) with peak loads of up to 100,000 requests per second across all platforms.

What to Cover

  1. API Contract & Synchronization Strategy: How quota status is transferred (e.g., dedicated polling vs. response headers in streaming SSE) and how the client tracks reset timestamps.
  2. Android Architecture: Client-side state machine (e.g., MVI/MVVM), persistence layer (Room/DataStore), and integration with Kotlin Coroutines/StateFlow across multiple UI components.
  3. Concurrency & Edge Cases: Race conditions when rapidly sending messages, speculative UI updates vs. rollbacks on 429s, and handling server-client time skew.

Hints

Hint 1

Avoid extra network round trips by piggybacking remaining quota and reset timestamps onto the headers or termination metadata of streaming response endpoints.

Hint 2

Rely on server-provided epoch timestamps rather than relative durations to eliminate client-side clock drift issues during countdowns.

Hint 3

Decouple quota tracking from individual chat screens into an application-scoped repository exposing an immutable `StateFlow`.

Follow-up questions

  • How would you handle quota accounting if a user cancels a streaming response after the first 3 tokens are generated?
  • If a user has both the Android app and the Web client open simultaneously, how do you prevent stale quota displays without aggressive polling?
  • How would you implement an optimistic local decrement to disable UI spamming while gracefully handling rollbacks if the network request fails?