What is the main purpose of rate limiting in system design?
Rate limiting controls how many requests a user or system can make in a given time to prevent overload and ensure fair resource use.
Click to reveal answer
beginner
Describe the Token Bucket algorithm in simple terms.
Token Bucket allows requests if there are tokens available. Tokens are added at a steady rate. Each request uses one token. If no tokens, request is denied or delayed.
Click to reveal answer
beginner
How does the Leaky Bucket algorithm control request flow?
Leaky Bucket processes requests at a fixed rate. Excess requests wait in a queue. If the queue is full, new requests are dropped.
Click to reveal answer
intermediate
What is a key difference between Token Bucket and Leaky Bucket algorithms?
Token Bucket allows bursts of requests up to token count, while Leaky Bucket smooths out bursts by processing at a constant rate.
Click to reveal answer
intermediate
Why might a system choose Token Bucket over Leaky Bucket for rate limiting?
Token Bucket is better for systems that allow short bursts of traffic, giving flexibility while still controlling average rate.
Click to reveal answer
Which rate limiting algorithm allows bursts of requests up to a token limit?
AToken Bucket
BLeaky Bucket
CFixed Window
DSliding Log
✗ Incorrect
Token Bucket allows bursts by accumulating tokens that can be spent quickly.
In the Leaky Bucket algorithm, what happens when the queue is full and a new request arrives?
AThe request is dropped
BThe request is processed immediately
CThe bucket refills tokens
DThe request is delayed indefinitely
✗ Incorrect
New requests are dropped if the queue is full to prevent overload.
Which algorithm processes requests at a fixed, steady rate?
ASliding Window
BToken Bucket
CLeaky Bucket
DFixed Window
✗ Incorrect
Leaky Bucket processes requests at a constant rate, smoothing bursts.
What does a token represent in the Token Bucket algorithm?
AA dropped request
BPermission to process one request
CA queued request
DA fixed time interval
✗ Incorrect
Each token allows one request to be processed.
Why is rate limiting important in distributed systems?
ATo reduce network latency
BTo increase request speed
CTo store more data
DTo prevent system overload and ensure fair use
✗ Incorrect
Rate limiting protects systems from overload and abuse.
Explain how the Token Bucket algorithm works and when it is useful.
Think of tokens as tickets to make requests.
You got /4 concepts.
Describe the Leaky Bucket algorithm and how it differs from Token Bucket.
Imagine water leaking from a bucket at a steady rate.
You got /5 concepts.
Practice
(1/5)
1. Which rate limiting algorithm allows short bursts of traffic by accumulating tokens over time?
easy
A. Token Bucket
B. Leaky Bucket
C. Fixed Window Counter
D. Sliding Log
Solution
Step 1: Understand token bucket behavior
The token bucket algorithm accumulates tokens at a fixed rate, allowing bursts when tokens are available.
Step 2: Compare with leaky bucket
The leaky bucket processes requests at a steady rate, smoothing bursts rather than allowing them.
3. Consider a token bucket with a capacity of 5 tokens and a refill rate of 1 token per second. Initially, the bucket is full. If 7 requests arrive instantly, how many requests will be allowed immediately?
medium
A. 5
B. 7
C. 1
D. 0
Solution
Step 1: Understand token bucket capacity and refill
The bucket starts full with 5 tokens, each request consumes one token.
Step 2: Calculate allowed requests
Since 7 requests arrive instantly but only 5 tokens are available, only 5 requests are allowed immediately.
Hint: Max allowed = tokens in bucket at request time [OK]
Common Mistakes:
Assuming all 7 requests allowed instantly
Ignoring token bucket capacity
Confusing refill rate with immediate tokens
4. A developer implemented a leaky bucket rate limiter but notices that bursts are still allowed. What is the most likely cause?
medium
A. The bucket capacity is set too low
B. Requests are dequeued faster than the leak rate
C. Tokens are refilled too quickly
D. The leak rate is set to zero
Solution
Step 1: Analyze leaky bucket behavior
Leaky bucket allows steady output by leaking requests at a fixed rate.
Step 2: Identify cause of bursts
If requests are dequeued faster than the leak rate, bursts can pass through, breaking the smoothing effect.
Final Answer:
Requests are dequeued faster than the leak rate -> Option B
Quick Check:
Dequeue rate > leak rate = bursts allowed [OK]
Hint: Leaky bucket bursts mean dequeue faster than leak rate [OK]
Common Mistakes:
Confusing token refill with leaky bucket
Assuming bucket capacity controls bursts
Ignoring dequeue speed vs leak rate
5. You need to design a rate limiter for an API that allows short bursts but enforces an average rate limit over time. Which algorithm should you choose and why?
hard
A. Leaky Bucket, because it smooths out bursts by processing requests steadily
B. Fixed Window Counter, because it counts requests in fixed intervals
C. Sliding Log, because it logs every request timestamp
D. Token Bucket, because it allows bursts by accumulating tokens and enforces average rate
Solution
Step 1: Understand requirement for bursts and average rate
The system must allow short bursts but keep average rate limited over time.
Step 2: Match algorithm to requirement
Token bucket allows bursts by using tokens that refill over time, enforcing average rate while permitting bursts.
Final Answer:
Token Bucket, because it allows bursts by accumulating tokens and enforces average rate -> Option D
Quick Check:
Bursts + average rate = Token Bucket [OK]
Hint: Token bucket = bursts + average rate control [OK]
Common Mistakes:
Choosing leaky bucket which smooths bursts
Confusing fixed window with burst allowance
Ignoring average rate enforcement
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.