Bird
Raised Fist0

How should you combine per-user and per-IP rate limits to block requests correctly when either limit is exceeded?

hard🚀 Application Q8 of Q15
Rest API - Rate Limiting and Throttling
How should you combine per-user and per-IP rate limits to block requests correctly when either limit is exceeded?
Aif requests_user >= user_limit and requests_ip >= ip_limit: block() else: allow()
Bif requests_user < user_limit and requests_ip < ip_limit: block() else: allow()
Cif requests_user >= user_limit or requests_ip >= ip_limit: block() else: allow()
Dif requests_user <= user_limit or requests_ip <= ip_limit: block() else: allow()
Step-by-Step Solution
Solution:
  1. Step 1: Understand the blocking condition

    Requests should be blocked if either the user or IP exceeds their respective limits.
  2. Step 2: Analyze logical operators

    Using 'or' ensures blocking if any limit is reached or exceeded.
  3. Final Answer:

    if requests_user >= user_limit or requests_ip >= ip_limit: block() else: allow() -> Option C
  4. Quick Check:

    Block if user OR IP limit exceeded [OK]
Quick Trick: Use OR to combine limits for blocking [OK]
Common Mistakes:
MISTAKES
  • Using AND instead of OR, blocking only if both limits exceeded
  • Reversing comparison operators
  • Blocking when limits are not exceeded

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes