Problem
Implement a token bucket rate limiter:
- The bucket holds at most
capacitytokens. - Tokens refill at
refillRatetokens per second (continuous refill). allowRequest(tokens = 1)returnstrueif enough tokens are available and deducts them; otherwisefalse.
Used to protect APIs from abuse while allowing short bursts.