SystemKit

Design rate limits and plan quotas for a public API

Apply the rate limiter chapter to two limits with different jobs: a per-second limit that protects capacity and a monthly quota that customers pay for.

The brief

A company sells a public API from three regions. Each API key has a per-second limit that protects the service and a monthly quota set by its paid plan. Design how requests are checked, how usage is counted across regions, and how customers learn where they stand. Keep the API’s own business logic, invoicing, and key issuance outside this exercise.

  • Traffic averages 1,000 requests per second across all keys, with a peak of 5 times the average. Use a 30-day month of 2,592,000 seconds and decimal units.
  • Plans: Free allows 10 requests per second and 1 million a month; Pro allows 100 per second and 50 million a month; Enterprise allows 1,000 per second and 1 billion a month. 50,000 keys are active in a month.
  • The API runs in 3 regions with traffic roughly even across them. A cross-region round trip takes 80 ms, and the limiter’s decision must add under 5 ms at p99.
  • The per-second limit protects capacity and may overshoot briefly. The monthly quota may overshoot by at most 0.1%, and usage that customers are billed for must not be lost.
  • Limiter state takes 120 bytes per key in each region. A raw usage record is 100 bytes; an hourly rollup per key and region is 50 bytes.

Reading a design isn’t the same as producing one under a clock. Try it timed: the requirement change stays hidden until partway through.

Loading your draft…

State your scope. Estimate monthly requests, peak decisions per region, limiter state, and usage storage. Work out how long a key at its full per-second limit takes to use its monthly quota, and compare the cross-region round trip with the decision budget.

0 / 4,000 characters

Name the components and what each stores. Trace one allowed request, one request rejected by the per-second limit, and one rejected by the monthly quota, including what each response tells the client.

0 / 4,000 characters

Work out the worst-case monthly overshoot for a key active in all three regions, given how often your regions sync. Then explain what happens if a regional counter store fails, and if one region is cut off from the others.

0 / 4,000 characters

Respond to the prepaid change below. Explain how a region decides it may serve a request, what happens near zero balance, and what a crashed region does to the customer’s remaining balance.

The requirement changesSales launches prepaid packs: a customer buys 10 million requests up front, and the contract forbids serving even one request beyond what was paid for. Customers can buy more at any time. How do you stop at exactly the limit without putting an 80 ms call on every request?

0 / 4,000 characters

Write an initial response in all four sections to unlock the checklist and two worked approaches.