🔍 1. Fixed Window Rate Limiting (in .NET)
What it is
The Fixed Window algorithm counts requests within a strict time window (like a box of time). When the window resets, the count resets too.
Example
- Limit: 10 requests per minute.
- Every minute (e.g., from 10:00:00 to 10:01:00), a new window opens.
- If a client makes 10 requests at 10:00:05, they are allowed.
- The next request (11th) before 10:01:00 will get blocked (HTTP 429 error).
- At 10:01:00, the window resets and they can make requests again.
In .NET
options.AddSlidingWindowLimiter("sliding", opt =>
{
opt.Window = TimeSpan.FromMinutes(1); // 1-minute rolling window
opt.PermitLimit = 10; // 10 requests allowed in the last minute
opt.SegmentsPerWindow = 4; // divide into 4 parts (15 seconds each)
opt.QueueProcessingOrder = QueueProcessingOrder.OldestFirst;
opt.QueueLimit = 2;
});
Pros
✔️ Very simple and fast to implement.
✔️ Good for low-traffic or non-critical APIs.
Cons
❌ Allows “burst traffic” at the start of the window (all 10 requests may come instantly).
❌ Not very "smooth" — users may hit the limit early and wait for the whole window.
🔍 2. Sliding Window Rate Limiting (in .NET)
What it is
The Sliding Window algorithm spreads the limit over a rolling period, not tied to a fixed block of time. It calculates how many requests were made in the last X minutes — no matter when the requests came.
Example
- Limit: 10 requests per minute (rolling).
- If 10 requests were made between 10:00:30 and 10:01:30, the limit applies based on that rolling window — not the wall clock.
- This avoids a sudden "burst" problem and gives a smoother, fairer limit.
In .NET
options.AddSlidingWindowLimiter("sliding", opt =>
{
opt.Window = TimeSpan.FromMinutes(1); // 1-minute rolling window
opt.PermitLimit = 10; // 10 requests allowed in the last minute
opt.SegmentsPerWindow = 4; // divide into 4 parts (15 seconds each)
opt.QueueProcessingOrder = QueueProcessingOrder.OldestFirst;
opt.QueueLimit = 2;
});

Join the conversation! Your thoughts help the community grow.