Fixed Window Counter
What you'll learn: How the fixed window counter algorithm divides time into discrete intervals to track and limit requests, and why its simplicity comes with a critical boundary problem.
Core Concept
The fixed window counter algorithm splits time into equal, non-overlapping intervals (windows) — say, 1-minute chunks. Each window has its own request counter that resets to zero when a new window begins.
For example, with a limit of 100 requests per minute:
- Window 1: 12:00:00 - 12:00:59
- Window 2: 12:01:00 - 12:01:59
- Window 3: 12:02:00 - 12:02:59
If a user makes 80 requests during window 1, they have 20 remaining. At 12:01:00, the counter resets, and they get a fresh 100-request allowance.
How It Works
When a request arrives:
- Determine the current time window
- Increment the counter for that window
- Allow the request if
counter <= limit - Reject if over the limit
- Reset counter when window boundary is crossed
The Boundary Spike Problem
Here's the critical flaw: fixed windows don't prevent burst traffic at boundaries.
Imagine a 100-requests-per-minute limit. A user could:
- Send 100 requests at 12:00:50 - 12:00:59 (allowed, within window 1)
- Send 100 requests at 12:01:00 - 12:01:09 (allowed, within window 2)
Result: 200 requests in 20 seconds — double the intended rate!
This happens because each window operates independently. The algorithm has no memory of what happened in the previous window, creating gaps in protection at boundaries.
Why Use It?
Despite this weakness, fixed window counters are:
- Simple to implement (just timestamp → window ID mapping)
- Memory efficient (one counter per window)
- Easy to reason about for users
Key Takeaway: Fixed window counters provide simple, efficient rate limiting but suffer from boundary spike problems where users can burst at twice the intended rate across window transitions.