Design a Distributed Rate Limiter
Design a multi-tenant distributed limiter that smooths priority and regular traffic under versioned quotas, retries, and partial failure.
Problem statement
For this exercise, assume an API platform needs per-tenant and optional per-route token-bucket quotas with priority and regular traffic classes. Every request receives a fast allow or reject decision.
A short rolling window smooths bursts; priority traffic may borrow unused regular capacity, while regular traffic may not consume reserved priority capacity. Operators must change policies safely, and the design must remain useful through retries, timeouts, hot keys, shard failures, and regional partitions.
Define class-specific retry guidance, availability behavior, and bounded overshoot rather than silently moving capacity between classes.
What to build
- Return an allow or reject decision for a tenant, route, traffic class, and request cost, including class-specific remaining capacity and retry guidance.
- Smooth short bursts while preserving reserved priority capacity and allowing priority traffic to borrow unused regular capacity.
- Let authorized operators create, version, roll back, and audit quota policies.
- Keep decisions available according to each policy's explicit fail-open or fail-closed posture while bounding overshoot.
At scale
- Sustain 1,000,000 decision requests per second globally with skewed tenant traffic and up to tenfold one-second bursts.
- Keep added decision latency below 5 ms at p99 within a region.
- Support 10,000,000 active quota keys and policy updates visible within 30 seconds.
- Bound global-quota overshoot during a regional partition to the tokens leased to affected regions, and prevent regular traffic from consuming reserved priority capacity.