Bird
Raised Fist0

Given a token bucket with max_tokens = 3, refill_rate = 1 token/second, and current tokens = 1, what will be the tokens after 2 seconds if no requests are made?

medium📝 Predict Output Q4 of Q15
Rest API - Rate Limiting and Throttling

Given a token bucket with max_tokens = 3, refill_rate = 1 token/second, and current tokens = 1, what will be the tokens after 2 seconds if no requests are made?

A3 tokens
B2 tokens
C1 token
D0 tokens
Step-by-Step Solution
Solution:
  1. Step 1: Calculate tokens added in 2 seconds

    Refill rate is 1 token per second, so 2 seconds add 2 tokens.
  2. Step 2: Add tokens to current and check max limit

    Current tokens = 1 + 2 = 3, which equals max_tokens, so bucket is full.
  3. Final Answer:

    3 tokens -> Option A
  4. Quick Check:

    Tokens capped at max_tokens [OK]
Quick Trick: Tokens refill but never exceed max capacity [OK]
Common Mistakes:
MISTAKES
  • Ignoring max_tokens limit
  • Not adding refill tokens
  • Subtracting tokens incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes