Bird
Raised Fist0

You want to implement a rate limiter that blocks requests if either the user or the IP address exceeds their limits. Which pseudocode correctly enforces this combined rule?

hard🚀 Application Q15 of Q15
Rest API - Rate Limiting and Throttling
You want to implement a rate limiter that blocks requests if either the user or the IP address exceeds their limits. Which pseudocode correctly enforces this combined rule?
Aif requests_per_user[user] > user_limit and requests_per_ip[ip] > ip_limit: block_request()
Bif requests_per_user[user] == user_limit and requests_per_ip[ip] == ip_limit: block_request()
Cif requests_per_user[user] < user_limit or requests_per_ip[ip] < ip_limit: block_request()
Dif requests_per_user[user] > user_limit or requests_per_ip[ip] > ip_limit: block_request()
Step-by-Step Solution
Solution:
  1. Step 1: Understand combined blocking logic

    The request should be blocked if either the user or the IP exceeds their limit, so the condition must use OR.
  2. Step 2: Check condition correctness

    if requests_per_user[user] > user_limit or requests_per_ip[ip] > ip_limit: block_request() uses OR with > comparisons, correctly blocking if user or IP exceeds limits.
  3. Final Answer:

    if requests_per_user[user] > user_limit or requests_per_ip[ip] > ip_limit: block_request() -> Option D
  4. Quick Check:

    Block if user OR IP exceeds limit [OK]
Quick Trick: Use OR to block if either user or IP exceeds limit [OK]
Common Mistakes:
MISTAKES
  • Using AND instead of OR
  • Using < instead of >
  • Checking equality only

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes