Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the Fixed Window Algorithm in rate limiting?
It is a method to limit the number of requests a user can make in a fixed time period, like allowing 100 requests per minute. If the limit is reached, further requests are blocked until the next time window starts.
Click to reveal answer
beginner
How does the Fixed Window Algorithm count requests?
It counts all requests within the current fixed time window, for example, from 12:00:00 to 12:00:59. When the window ends, the count resets to zero for the next window.
Click to reveal answer
intermediate
What is a downside of the Fixed Window Algorithm?
It can cause bursts of traffic at the edges of windows. For example, a user can send the maximum allowed requests at the end of one window and again at the start of the next, effectively doubling the allowed rate temporarily.
Click to reveal answer
beginner
In the Fixed Window Algorithm, what happens when the request count exceeds the limit?
The system rejects or delays further requests until the current time window ends and the count resets.
Click to reveal answer
beginner
Why is the Fixed Window Algorithm easy to implement?
Because it only needs to track the count of requests in a simple fixed time window, without complex calculations or storing timestamps for each request.
Click to reveal answer
What does the Fixed Window Algorithm use to limit requests?
AA fixed time period to count requests
BA sliding time window
CRandom request sampling
DUser IP address only
✗ Incorrect
The Fixed Window Algorithm counts requests in a fixed time period, like one minute.
What happens when the request count reaches the limit in a fixed window?
ARequests are always allowed
BRequests are blocked until the window resets
CRequests are queued indefinitely
DThe limit increases automatically
✗ Incorrect
Once the limit is reached, further requests are blocked until the next time window.
What is a common problem with the Fixed Window Algorithm?
AIt allows bursts of requests at window edges
BIt requires complex calculations
CIt never resets the count
DIt blocks all requests
✗ Incorrect
Users can send many requests at the end of one window and start of the next, causing bursts.
Which of these is NOT true about the Fixed Window Algorithm?
AIt limits requests per fixed time period
BIt resets the count after each time window
CIt is simple to implement
DIt tracks requests individually with timestamps
✗ Incorrect
The Fixed Window Algorithm does not track individual timestamps, only counts per window.
Why might someone choose the Fixed Window Algorithm?
ABecause it perfectly smooths request rates
BBecause it never blocks requests
CBecause it is easy and fast to implement
DBecause it tracks each request's exact time
✗ Incorrect
Its simplicity and speed make it a common choice despite some limitations.
Explain how the Fixed Window Algorithm controls the number of API requests.
Think about counting requests in a set time and what happens when the limit is reached.
You got /4 concepts.
Describe one advantage and one disadvantage of the Fixed Window Algorithm.
Consider simplicity and how traffic might spike.
You got /2 concepts.
Practice
(1/5)
1.
What is the main idea behind the Fixed window algorithm in rate limiting?
easy
A. Count requests in fixed time intervals and block if limit exceeded
B. Allow unlimited requests without any restrictions
C. Count requests over a sliding time window for smooth limiting
D. Block all requests after the first one
Solution
Step 1: Understand fixed window concept
The fixed window algorithm divides time into fixed intervals (windows) and counts requests in each interval.
Step 2: Identify how blocking works
If the number of requests in the current window exceeds the limit, further requests are blocked until the next window.
Final Answer:
Count requests in fixed time intervals and block if limit exceeded -> Option A
Quick Check:
Fixed window = count + block in fixed intervals [OK]
Hint: Fixed window counts requests per fixed time block [OK]
Common Mistakes:
Confusing fixed window with sliding window algorithm
Thinking it allows unlimited requests
Assuming it blocks all requests immediately
2.
Which of the following is the correct way to check the current window start time in a fixed window algorithm using Python?
C. Remove the if condition checking time difference
D. Move window_start update inside the if block to reset window
Solution
Step 1: Identify window reset logic
The code resets count when window expires but does not update window_start, so window never moves forward.
Step 2: Fix by updating window start time
Inside the if block, update window_start = int(time.time()) to start a new window correctly.
Final Answer:
Move window_start update inside the if block to reset window -> Option D
Quick Check:
Reset count and window start together [OK]
Hint: Update window start when resetting count [OK]
Common Mistakes:
Not updating window start time
Resetting count incorrectly
Ignoring time difference condition
5.
You want to implement a fixed window rate limiter that allows 10 requests per minute per user. Which approach correctly handles multiple users without mixing counts?
hard
A. Store counts in a list without user identification
B. Use a dictionary with user IDs as keys and counts as values, reset counts per user each window
C. Use a single global count for all users and reset every minute
D. Allow unlimited requests for all users
Solution
Step 1: Understand per-user counting
Each user must have a separate count to avoid mixing requests between users.
Step 2: Use dictionary keyed by user ID
A dictionary with user IDs as keys and counts as values allows tracking each user's requests independently and resetting counts per window.
Final Answer:
Use a dictionary with user IDs as keys and counts as values, reset counts per user each window -> Option B
Quick Check:
Separate counts per user = dictionary keyed by user [OK]
Hint: Track counts per user with dictionary keys [OK]