0
0
HLDsystem_design~10 mins

Rate limiting algorithms (token bucket, leaky bucket) in HLD - Interactive Code Practice

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

Complete the code to represent the token bucket refill logic.

HLD
tokens = min(capacity, tokens + [1] * elapsed_time)
Drag options to blanks, or click blank then click option'
Arate
Bcapacity
Ctokens
Delapsed_time
Attempts:
3 left
💡 Hint
Common Mistakes
Using capacity instead of rate
Adding tokens without considering elapsed time
2fill in blank
medium

Complete the code to check if a request can be allowed in the leaky bucket algorithm.

HLD
if queue_size < [1]:
    allow_request()
Drag options to blanks, or click blank then click option'
Acapacity
Brate
Ctokens
Delapsed_time
Attempts:
3 left
💡 Hint
Common Mistakes
Using rate instead of capacity
Ignoring queue size
3fill in blank
hard

Fix the error in the token bucket token consumption logic.

HLD
if tokens >= [1]:
    tokens -= request_size
Drag options to blanks, or click blank then click option'
Atokens
Brequest_size
Ccapacity
Drate
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing tokens with capacity
Subtracting rate instead of request size
4fill in blank
hard

Fill both blanks to implement the leaky bucket leak rate update.

HLD
leaked = min(queue_size, [1] * [2])
queue_size -= leaked
Drag options to blanks, or click blank then click option'
Arate
Belapsed_time
Ccapacity
Dtokens
Attempts:
3 left
💡 Hint
Common Mistakes
Using capacity instead of rate
Using tokens instead of elapsed time
5fill in blank
hard

Fill all three blanks to implement a token bucket request check and update.

HLD
if tokens >= [1]:
    tokens -= [2]
    allow = [3]
Drag options to blanks, or click blank then click option'
Arequest_size
CTrue
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Setting allow to False incorrectly
Subtracting wrong value from tokens