0
0
HLDsystem_design~20 mins

Rate limiting algorithms (token bucket, leaky bucket) in HLD - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Rate Limiting Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Token Bucket Algorithm Behavior

Consider a token bucket rate limiter with a bucket capacity of 5 tokens and a refill rate of 1 token per second. Initially, the bucket is full. If 7 requests arrive instantly at time 0, how many requests will be allowed immediately?

A2 requests allowed immediately, 5 requests rejected
B7 requests allowed immediately
C0 requests allowed immediately, all queued
D5 requests allowed immediately, 2 requests rejected
Attempts:
2 left
💡 Hint

Think about how many tokens are available at the start and how many requests consume tokens.

Architecture
intermediate
2:00remaining
Choosing Between Token Bucket and Leaky Bucket

You are designing an API gateway that needs to limit request bursts but also smooth out traffic spikes over time. Which rate limiting algorithm is more suitable?

AToken Bucket, because it allows bursts up to bucket capacity
BLeaky Bucket, because it allows bursts up to bucket capacity
CLeaky Bucket, because it allows unlimited bursts
DToken Bucket, because it enforces a fixed output rate regardless of bursts
Attempts:
2 left
💡 Hint

Consider which algorithm allows bursts and which smooths traffic strictly.

scaling
advanced
2:00remaining
Scaling Rate Limiter for Distributed Systems

You need to implement a distributed rate limiter using the token bucket algorithm across multiple servers. What is the main challenge and best approach?

AChallenge: High memory usage; Approach: Store tokens locally on each server without synchronization
BChallenge: Synchronizing token counts; Approach: Use a centralized token store with atomic operations
CChallenge: Network latency; Approach: Use local caches and ignore synchronization
DChallenge: Token overflow; Approach: Increase bucket size infinitely
Attempts:
2 left
💡 Hint

Think about consistency of token counts across servers.

tradeoff
advanced
2:00remaining
Tradeoffs Between Token Bucket and Leaky Bucket

Which statement correctly describes a tradeoff between token bucket and leaky bucket algorithms?

AToken bucket allows bursty traffic but can cause uneven output; leaky bucket smooths output but rejects bursts
BLeaky bucket allows bursty traffic but can cause uneven output; token bucket smooths output but rejects bursts
CBoth algorithms allow unlimited bursts but differ in refill rates
DToken bucket rejects all bursts; leaky bucket allows bursts up to bucket size
Attempts:
2 left
💡 Hint

Recall how each algorithm handles bursts and output rate.

estimation
expert
2:00remaining
Estimating Capacity for Rate Limiter with Token Bucket

You have a token bucket rate limiter with a bucket size of 100 tokens and a refill rate of 10 tokens per second. What is the maximum number of requests that can be served in a 15-second window assuming the bucket starts full and requests arrive uniformly?

A100 requests
B150 requests
C250 requests
D50 requests
Attempts:
2 left
💡 Hint

Calculate total tokens available: initial tokens plus tokens refilled over time.