0
0
Microservicessystem_design~10 mins

Rate limiting in Microservices - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define the maximum number of requests allowed per user.

Microservices
MAX_REQUESTS_PER_MINUTE = [1]
Drag options to blanks, or click blank then click option'
A1000
B100
C10
D10000
Attempts:
3 left
💡 Hint
Common Mistakes
Setting the limit too high causing server overload.
Setting the limit too low causing poor user experience.
2fill in blank
medium

Complete the code to check if the user has exceeded the rate limit.

Microservices
if user_requests > [1]:
    block_request()
Drag options to blanks, or click blank then click option'
AMAX_REQUESTS_PER_HOUR
BMAX_REQUESTS_PER_SECOND
CMAX_REQUESTS_PER_MINUTE
DMAX_REQUESTS_TOTAL
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong time window limit variable.
Comparing against a total or hourly limit instead of per-minute.
3fill in blank
hard

Fix the error in the code that resets the request count after the time window.

Microservices
if current_time - window_start >= [1]:
    reset_request_count()
Drag options to blanks, or click blank then click option'
A1
B3600
C600
D60
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3600 seconds which is 1 hour instead of 1 minute.
Using 600 seconds which is 10 minutes.
4fill in blank
hard

Fill both blanks to implement a sliding window rate limiter using timestamps.

Microservices
request_times = [t for t in request_times if t > current_time - [1]]
if len(request_times) >= [2]:
    block_request()
Drag options to blanks, or click blank then click option'
A60
B100
C120
D50
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the time window and max request count values.
Using a time window longer than the defined rate limit period.
5fill in blank
hard

Fill all three blanks to implement token bucket rate limiting logic.

Microservices
tokens = min(capacity, tokens + (current_time - last_checked) * [1])
if tokens < [2]:
    block_request()
else:
    tokens -= [3]
Drag options to blanks, or click blank then click option'
Arefill_rate
B1
Ctoken_cost
Dcapacity
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing capacity with refill_rate.
Using token_cost incorrectly in comparison or subtraction.