Bird
0
0

A developer wrote this pseudocode for rate limiting but it doesn't work correctly:

medium📝 Debug Q6 of 15
Rest API - Rate Limiting and Throttling
A developer wrote this pseudocode for rate limiting but it doesn't work correctly:
requests = 0
limit = 10
for each request:
  if requests < limit:
    process request
  else:
    reject request
  requests += 1

What is the main problem?
AThe requests counter is incremented before checking the limit.
BThe limit variable is too high.
CThe code does not reject any requests.
DThe requests counter is never reset, so limit is reached once and never reset.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the requests counter usage

    The counter increases but never resets, so after 10 requests all are rejected.
  2. Step 2: Understand rate limiting needs reset

    Rate limits usually reset after a time window; missing reset causes permanent blocking.
  3. Final Answer:

    The requests counter is never reset, so limit is reached once and never reset. -> Option D
  4. Quick Check:

    Missing reset causes permanent limit hit = C [OK]
Quick Trick: Reset request count after time window to avoid permanent block [OK]
Common Mistakes:
  • Thinking limit value is the problem
  • Incrementing counter before check (actually after)
  • Believing code never rejects requests

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes