Quick revision
The short answer
Short-term rate limits per second and per minute are enforced at the gateway in each region, close to clients, using regional counters that tolerate a little drift. Monthly quotas are a different problem: they are computed from usage events in a metering pipeline, off the request path, and the same metered data feeds billing so limits and invoices always agree. Plan changes reach the gateways as configuration with short caching, and customers see their limits through response headers and a usage dashboard.
What to remember
In this answer, we split the problem into fast rate limits and slow quotas. Rate limits are enforced at regional gateways with token buckets and drift that we document, quotas come from a deduplicated metering pipeline off the request path, plan changes arrive as cached configuration with change events, billing reads the same metered data so limits and invoices agree, and headers plus a dashboard show customers exactly where they stand.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Short-term rate limits per second and per minute are enforced at the gateway in each region, close to clients, using regional counters that tolerate a little drift. Monthly quotas are a different problem: they are computed from usage events in a metering pipeline, off the request path, and the same metered data feeds billing so limits and invoices always agree. Plan changes reach the gateways as configuration with short caching, and customers see their limits through response headers and a usage dashboard.
Why this question is asked
A public API with paid plans turns rate limiting from a protection mechanism into part of the product. Free users must not degrade service for enterprise customers, enterprise customers must get what they pay for, and the invoice at the end of the month must match what the API allowed. Doing this across several regions adds the hardest part: we cannot afford a synchronous global counter on every request. Interviewers ask this question to see whether we separate concerns that look similar but have very different time scales and correctness needs. In this answer, we will separate rate limits from quotas, place each one in the architecture, handle plan changes, run in multiple regions, connect metering to billing, and show customers where they stand.
1Rate Limits and Quotas Are Different Problems
The two words are often mixed up, so we start by separating them. A rate limit controls speed over a short window: 50 requests per second on the free plan, 500 on standard, 5,000 on enterprise. It protects the platform from bursts and must be decided in a millisecond, on every request. A quota controls volume over a long period: 100,000 calls per month on free, 10 million on standard. It is about commercial fairness and billing, and being exact to the second does not matter.
This difference drives the whole design. Rate limits belong in the gateway, on the request path, with fast and approximate counters. Quotas belong in a metering pipeline that counts usage events after the fact, accurately, and then tells the gateway when a customer has run out.
| Rate limit | Quota | |
|---|---|---|
| Window | 1 second, 1 minute | billing month |
| Purpose | protect capacity | commercial plan and billing |
| Where decided | gateway, per request | metering pipeline, after the fact |
| Accuracy needed | approximate is fine | exact, it becomes an invoice |
| Across regions | per region, tolerated drift | aggregated globally |
2Enforcing Rate Limits at the Gateway in Each Region
Every region runs its own gateway layer, and each one enforces per-second and per-minute limits with a token bucket per API key, backed by a regional Redis. Enforcing close to clients means rejected traffic never reaches our services, and the check stays inside the region, so it costs well under a millisecond.
Services behind the gateway may still enforce their own internal limits, for example on an expensive report endpoint, but the plan limits live in one place. That keeps the rules consistent: a customer cannot get different answers from two services about how fast they may call.
3Running in Several Regions With Tolerated Drift
Now the multi-region question. A customer can send traffic to Europe and the United States at the same time. A truly global per-second counter would need a cross-region call on every request, adding 80 to 150 ms and making every region depend on the others. That is a bad trade for a limit whose purpose is protection, not accounting.
So we keep regional counters. One simple approach gives each region the full per-second limit, accepting that a customer who spreads traffic across three regions can reach up to three times the limit for short periods. A better one splits the limit by observed traffic share, for example 70 percent to the region that receives most of a customer's traffic, and rebalances every minute from gossiped usage numbers. Either way, we document the drift as a known property: per-second limits are enforced per region and are approximate across regions. Each region's capacity is planned for its own share, which is what protection actually needs.
4Monthly Quotas From a Metering Pipeline
For quotas, every request the gateway allows produces a small usage event: API key, plan, endpoint, region, timestamp, response status and a unique request id. The gateway writes these to a local buffer and publishes them in batches to Kafka in its region, never blocking the request. A metering service consumes the events, removes duplicates by request id, and aggregates usage per customer per hour into a durable store. Regional totals are combined into one global total per customer.
When a customer passes their quota, the metering service publishes a quota state change, and the gateways cache it. From then on the gateway either rejects with a clear error, applies a slower overage rate, or allows and bills overage, depending on the plan. Because metering lags by seconds to a minute, a customer may go a little over the quota before the block lands. That is acceptable, and the plan can define overage pricing so it is not a loss.
- Gateway checks regional rate limittoken bucket in regional Redis
- Within limit?YesForward to the serviceNoReject with 429 and Retry-After
- Gateway emits a usage eventbatched to regional Kafka, off the request path
- Metering deduplicates and aggregatesper customer, per hour, all regions
- Quota used up?YesPublish quota state to gatewaysNoKeep counting
- Billing reads the same aggregatesinvoice matches what was allowed
6 steps in order. Play them, or step through them one at a time.
5Plan Changes as Configuration, and Billing From the Same Data
When a customer upgrades from standard to enterprise, the new limits should apply within a minute, not at the next deployment. Plans and per-customer overrides live in a plan service. Gateways cache the plan for each API key for a short time, 30 to 60 seconds, and the plan service also publishes change events so caches are refreshed sooner. If the plan service is unavailable, gateways keep using the cached plan, which is far better than rejecting everyone.
Billing must read the same metering data that drives quota enforcement. If billing counted requests from service logs while quotas came from gateway events, the two numbers would differ, and customers would dispute invoices that disagree with the limits they saw. With one source, the dashboard, the quota block and the invoice all show the same 10,000,312 calls.
6Showing Customers Where They Stand
Customers cannot respect limits they cannot see. Every response carries headers with the current limit, the remaining requests in the window and when the window resets, and a 429 includes Retry-After. Many APIs use names such as X-RateLimit-Limit, and there is an IETF draft for standard RateLimit headers; we pick one convention and document it.
For quotas, a usage dashboard shows calls per day and the percentage of the monthly quota used, and the platform sends warnings at 80 and 100 percent. This turns a surprise block into a planned upgrade, which is good for the customer and for sales.
7Follow-up questions
Why not use one global Redis for all regions?
Every request would wait for a cross-region round trip, and a network problem between regions would break rate limiting everywhere. Per-second limits exist to protect local capacity, so regional enforcement with tolerated drift gives the protection without the latency and coupling.
How do you avoid double counting usage events?
Each event carries a unique request id, and the metering consumer deduplicates on it within a window, for example by keeping recent ids or by using an idempotent upsert keyed by request id. Kafka delivers at least once, so deduplication is required for invoices to be correct.
What happens to usage events if Kafka is down in a region?
The gateway buffers events locally on disk for a while and publishes them when Kafka recovers. Requests keep flowing. We alert on buffer size, because losing events means losing revenue and quota accuracy.
8Conclusion
In this answer, we split the problem into fast rate limits and slow quotas. Rate limits are enforced at regional gateways with token buckets and drift that we document, quotas come from a deduplicated metering pipeline off the request path, plan changes arrive as cached configuration with change events, billing reads the same metered data so limits and invoices agree, and headers plus a dashboard show customers exactly where they stand.
Open with
I would start by separating rate limits from quotas. Rate limits, per second and per minute, protect capacity and must be decided on every request in a millisecond, so the gateway in each region enforces them with token buckets in a regional Redis.
Then, if they want more
Quotas, like 10 million calls a month, are commercial, need to be exact, and do not need to be decided synchronously, so every allowed request emits a usage event to Kafka and a metering service deduplicates and aggregates them per customer across all regions.
When a quota is exhausted, metering publishes that state and the gateways cache it and block or apply overage pricing. For multi-region, I would not build a global synchronous counter, because it adds cross-region latency to every call; instead each region gets a share of the limit with some documented drift.
Plans live in a plan service; gateways cache them for about a minute and also listen for change events, so an upgrade applies quickly. Billing reads the same metering data, so the invoice matches what the quota allowed.
Finally, I would return limit and remaining headers plus Retry-After on 429, and give customers a usage dashboard with alerts at 80 and 100 percent.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Your company offers a public API with free, standard and enterprise plans. Design the...": https://scrivio-interview-library.netlify.app/architecture/backend-system-design/fae404c2f9/