Bird
0
0

Consider this pseudo-code for a fixed window rate limiter with a limit of 3 requests per 10 seconds:

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

Consider this pseudo-code for a fixed window rate limiter with a limit of 3 requests per 10 seconds:

window_size = 10
limit = 3
requests = [timestamp1, timestamp2, timestamp3, timestamp4]

If the first three requests happen at seconds 1, 5, and 9, and the fourth at second 11, which requests are allowed?

AOnly first three allowed, fourth blocked
BFirst three allowed, fourth allowed (new window)
CAll four allowed
DOnly first two allowed, others blocked
Step-by-Step Solution
Solution:
  1. Step 1: Identify windows for requests

    Requests at seconds 1, 5, 9 fall in window 0-10 seconds; fourth at 11 is in next window 10-20 seconds.
  2. Step 2: Check limits per window

    First window allows 3 requests, so first three allowed; fourth request is in new window, so allowed.
  3. Final Answer:

    First three allowed, fourth allowed (new window) -> Option B
  4. Quick Check:

    Requests reset each window = Allowed if under limit [OK]
Quick Trick: Requests reset count after each window ends [OK]
Common Mistakes:
  • Blocking fourth request incorrectly
  • Counting all requests in one window
  • Allowing more than limit in one window

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes