Bird
Raised Fist0

Consider this pseudocode for a rate limiter:

medium📝 Predict Output Q13 of Q15
Rest API - Rate Limiting and Throttling
Consider this pseudocode for a rate limiter:
requests = 0
limit = 3
for request in incoming_requests:
    if requests < limit:
        process(request)
        requests += 1
    else:
        reject(request)
What happens when 5 requests arrive quickly?
AOnly 3 requests are processed; 2 are rejected
BAll 5 requests are processed
CNo requests are processed
DOnly the first request is processed; others are rejected
Step-by-Step Solution
Solution:
  1. Step 1: Understand the limit and counter

    The limit is 3, and requests start at 0. Each processed request increments the counter.
  2. Step 2: Trace the 5 incoming requests

    First 3 requests meet requests < limit, so processed. The 4th and 5th exceed limit, so rejected.
  3. Final Answer:

    Only 3 requests are processed; 2 are rejected -> Option A
  4. Quick Check:

    Limit 3 means max 3 processed [OK]
Quick Trick: Count processed requests up to limit, reject rest [OK]
Common Mistakes:
MISTAKES
  • Assuming all requests are processed
  • Ignoring the requests counter increment
  • Thinking only one request is allowed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes