Problem Statement
How would you design per-tenant quotas (per second, per day) with burst allowance?
Explanation
Use token buckets for short-term control and a separate rolling counter for daily caps. The request must pass both checks. Tokens refill each second; the daily counter is a sliding window or a single counter with TTL aligned to a 24-hour window.
Keep limits in a shared store with atomic updates. Expose admin APIs to change tiers, and return headers so clients can back off. Shadow-test new limits before enforcing them to avoid surprising customers.
Code Solution
SolutionRead Only
allow = bucket.allow(req) && dailyCounter.withinLimit(tenant);
