Consider a token bucket rate limiter with a bucket capacity of 5 tokens and a refill rate of 1 token per second. Initially, the bucket is full. If 7 requests arrive instantly at time 0, how many requests will be allowed immediately?
Think about how many tokens are available at the start and how many requests consume tokens.
The bucket starts full with 5 tokens. Each request consumes one token. So, 5 requests can be served immediately. The remaining 2 requests have no tokens and are rejected or delayed.
You are designing an API gateway that needs to limit request bursts but also smooth out traffic spikes over time. Which rate limiting algorithm is more suitable?
Consider which algorithm allows bursts and which smooths traffic strictly.
Token Bucket allows bursts up to the bucket capacity by accumulating tokens. Leaky Bucket enforces a fixed output rate, smoothing traffic but not allowing bursts.
You need to implement a distributed rate limiter using the token bucket algorithm across multiple servers. What is the main challenge and best approach?
Think about consistency of token counts across servers.
Distributed token bucket requires synchronizing token counts to avoid allowing more requests than the limit. A centralized store with atomic operations ensures consistency.
Which statement correctly describes a tradeoff between token bucket and leaky bucket algorithms?
Recall how each algorithm handles bursts and output rate.
Token bucket allows bursts by accumulating tokens, which can cause uneven output. Leaky bucket enforces a steady output rate, smoothing traffic but rejecting bursts.
You have a token bucket rate limiter with a bucket size of 100 tokens and a refill rate of 10 tokens per second. What is the maximum number of requests that can be served in a 15-second window assuming the bucket starts full and requests arrive uniformly?
Calculate total tokens available: initial tokens plus tokens refilled over time.
Total tokens = initial bucket size (100) + refill rate (10 tokens/sec) * 15 seconds = 100 + 150 = 250 tokens, so 250 requests can be served.