Bird
0
0

If a client sends 15 requests instantly after being idle for 3 seconds, how many requests will be allowed immediately?

hard📝 Application Q15 of 15
Rest API - Rate Limiting and Throttling

You want to implement a token bucket that allows bursts of up to 10 requests and refills tokens at 2 tokens per second. If a client sends 15 requests instantly after being idle for 3 seconds, how many requests will be allowed immediately?

A6 requests
B5 requests
C15 requests
D10 requests
Step-by-Step Solution
Solution:
  1. Step 1: Calculate tokens available after 3 seconds idle

    Refill rate is 2 tokens/second, so after 3 seconds: 2 * 3 = 6 tokens. Max tokens allowed is 10, so bucket fills to 6 tokens.
  2. Step 2: Consider burst capacity

    Since the bucket max is 10, if it was full before idle, it would have 10 tokens. But starting empty, after 3 seconds it has 6 tokens.
  3. Step 3: Determine allowed requests

    The client sends 15 requests instantly, but only 6 tokens are available, so only 6 requests allowed immediately.
  4. Final Answer:

    6 requests -> Option A
  5. Quick Check:

    3 sec * 2 tokens/sec = 6 tokens available [OK]
Quick Trick: Tokens = min(max_tokens, refill_rate * idle_time) [OK]
Common Mistakes:
  • Assuming bucket always full at max tokens
  • Allowing more requests than tokens available
  • Ignoring refill rate and idle time

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes