← Questions

Design per-user model usage quotas for a mobile app

0
OpenAISystem designLast asked May 2026

A system design interview question asked in OpenAI's technical screen (coding), last asked May 2026. It tests mobile, quotas and rate limiting.

Design per-user quotas on model usage for a mobile (Android) app. Each user may send a limited number of model requests in a period. Design both sides: the server API and storage that count usage and enforce the limit atomically, and the Android client that shows how much is left, warns as the user nears the limit, blocks gracefully at it, and stays in agreement with the server.

Requirements

  • Functional: an API to read the remaining quota and its reset time; every model request checked and counted against the quota; a clear response when the quota is used up; the client showing remaining usage, a warning near the limit and a blocked state with the reset time.
  • Non-functional: the server is the source of truth and never lets two concurrent requests both take the last unit; quota checks add little latency; the client stays correct across several devices, retries, app restarts and offline periods.

Clarifying questions

  • What is counted: requests, tokens, or cost? Different models with different weights?
  • Fixed reset (daily at midnight in which time zone?) or a rolling window?
  • Do failed or cancelled requests count?
  • Can a user be signed in on several devices at once?
  • Are there plans with different limits, and can a user upgrade mid-period?

What a strong answer covers

  • An API contract: GET /quota returning {limit, used, remaining, resets_at}, and every model response (and a 429 quota_exceeded error) carrying the same fields so the client never has to guess.
  • Atomic enforcement: a conditional increment (UPDATE … SET used = used + 1 WHERE used < limit, or a Redis script) or reserve-then-commit for requests whose cost is known only at the end; refunds for failed requests; idempotency keys so a retried request is not counted twice.
  • Concurrency reasoning: two devices sending at once, clock and time-zone issues at reset, a cache in front of the counter.
  • The client as a reflection of server state: a repository holding the last known quota, updated from every response, exposed to the UI as state (StateFlow in a ViewModel); optimistic decrement only for display, corrected by the server.
  • UI states and effects: normal, warning (for example under 10% left), blocked with a countdown to reset, upgrade prompt as a one-off event; refresh on app start and when returning to the foreground.

Follow-ups

  • Move from request counts to token-based quotas where the cost is known only after the reply streams.
  • The quota service is down: fail open or fail closed, and for whom?
  • Add an admin override that grants extra quota immediately on every device.
  • How do you test the race where two devices take the last unit?

Where it's asked

  • OpenAI · Technical screen: coding · Last asked May 202660 min · One problem in three to five growing parts filling the hour, usually in CoderPad; ML roles get a Colab notebook with autocomplete off · No AI assistants or autocomplete; documentation is fine

What it tests

mobile · quotas · rate limiting · llm

Your canvas
Draw your answer hereBoxes, arrows and notes, saved for you to come back to.Sign in to start drawing