Design Token-Per-Minute Rate Limits for Organizations Using the API

Last updated: November 29, 2026

Quick Overview

Design a rate limiter that enforces requests-per-minute and tokens-per-minute limits per organization and model, where the true output token count is unknown until the response finishes.

OpenAI
System Design
Software Engineer
OpenAI
November 29, 2026
Software Engineer
System Design Round
System Design
Hard

0

0

0 solved


Design a rate limiter that enforces requests-per-minute and tokens-per-minute limits per organization and model, where the true output token count is unknown until the response finishes.

OpenAI's API publishes usage tiers with RPM and TPM limits per model, and enforcing them is unusual because cost is only fully known after generation. Interviewers want to see estimation plus reconciliation, a globally consistent enough counter, and helpful headers for developers.

What the Interviewer Expects
  • Explain why token limits differ from classic request limits
  • Reserve an estimate up front (input tokens plus max_tokens) and settle after completion
  • Pick an algorithm (token bucket or sliding window) and a counter store
  • Keep checks fast across many regions with limited cross-region coordination
  • Return 429s with retry hints and x-ratelimit headers
  • Protect shared GPU capacity separately from per-customer fairness
Key Topics to Cover
token bucket
distributed counters
estimation and reconciliation
Redis
fairness
How to Approach This
  1. Start by clarifying functional and non-functional requirements with the interviewer.
  2. Estimate the scale: QPS, storage, bandwidth. This drives your design decisions.
  3. Draw a high-level architecture first, then deep dive into 1-2 critical components.
  4. Discuss trade-offs explicitly (e.g., consistency vs availability, SQL vs NoSQL).
  5. Address failure scenarios, monitoring, and how the system handles 10x traffic spikes.
Possible Follow-up Questions
  • What if a customer sets max_tokens to 100k but typically uses 200?
  • How do you enforce a limit shared across five regions without a global lock?
  • How do batch and priority tiers interact with these limits?
  • How would you test that the limiter is fair under load?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements
  • Limits per (org, model_family): RPM, TPM, and daily caps for some tiers; project-level sub-limits optional.
  • Decision latency under 2 ms p99; millions of decisions per second.
  • Small overshoot (...
High-Level Design
  • API gateway calls a limiter client library that talks to a regional limiter service backed by sharded Redis (or in-memory with replication), keyed by org:model.
  • Tier config servi...

Submit Your Answer
Markdown supported