⚙️ Fix Rate Limiting Counting Requests Per Instance Instead of Per Deployment
The built-in rate limiting middleware’s fixed window, sliding window, and token bucket limiters all keep their counters in that process’s own memory by default. The moment the app runs behind a load balancer across more than one instance, each instance enforces the configured limit entirely independently against only the requests it personally received, so a client whose traffic happens to spread across N instances transparently gets up to N times the intended limit – with the configuration itself still looking completely correct in code.
⚙️ The Problem
builder.Services.AddRateLimiter(options =>
{
// In-memory partition store - correct per process, but each of
// N load-balanced instances enforces this limit independently
// against only the requests that instance personally received.
options.AddFixedWindowLimiter("api", opt =>
{
opt.PermitLimit = 100;
opt.Window = TimeSpan.FromMinutes(1);
});
});
✅ Fix: Move the Counter Somewhere Every Instance Can See It
- For any limit meant to apply per client or API key across the whole deployment, move the counter state to a shared store – a Redis-backed partition counter, or a distributed-cache-backed custom limiter – instead of the default in-memory partitions, which are explicitly documented as per-process.
- If true cross-instance exactness genuinely matters, such as a billing-grade quota rather than general abuse mitigation, enforce the hard limit at a layer that actually sees all instances’ traffic together, like an API gateway or reverse proxy in front of the cluster, and treat the in-app limiter as a secondary, best-effort guard.
- Load-test with traffic deliberately spread across every running instance in staging before trusting a configured limit number in production, since a single-instance load test can never reveal this gap.
🚨 Why This Is Dangerous
- Shipping a “100 requests per minute” limit that’s quietly 100 times N instances in production can leave an API wide open to the exact abuse pattern the limiter was added to stop, while the code review sees nothing wrong with the configuration at all.
A rate limit enforced per process isn’t a weaker rate limit – behind more than one instance, it’s a different one than the number in the code suggests.

