Bird
0
0

Find the bug in this fixed window rate limiter code:

medium📝 Debug Q7 of 15
Rest API - Rate Limiting and Throttling

Find the bug in this fixed window rate limiter code:

window_size = 30
limit = 3
window_start = int(time.time()) // window_size * window_size
count = 0
if time.time() < window_start + window_size:
count += 1
else:
count = 0

AWindow start calculation is incorrect
BTime comparison uses less than instead of less or equal
CLimit is not checked anywhere
DCount resets after window ends, but current request not counted
Step-by-Step Solution
Solution:
  1. Step 1: Check count reset logic

    When window ends, count resets to zero but current request is not counted.
  2. Step 2: Identify fix

    After reset, count should be set to 1 to count current request.
  3. Final Answer:

    Count resets after window ends, but current request not counted -> Option D
  4. Quick Check:

    Reset count must include current request [OK]
Quick Trick: Reset count to 1, not 0, for new window request [OK]
Common Mistakes:
  • Forgetting to count current request after reset
  • Incorrect window start calculation
  • Not checking limit at all

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes