Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio
Asp.Net Core

Asp.Net Core: Fix a Rate Limiter Resetting Its Window Too Early

- 29.11.26 - ErcanOPAK

⚙️ Fix a Rate Limiter Resetting Its Window Too Early

The built-in System.Threading.RateLimiting middleware’s FixedWindowLimiter tracks its window entirely in the memory of whichever process instance handled the request, keyed per partition. That’s fine for a single instance, but behind a load balancer distributing traffic across several replicas, each replica keeps its own independent window and its own independent count — so a client that gets routed to a different instance on its next request effectively gets a brand new, unused rate limit window there, letting it exceed the limit you configured simply by virtue of which instance happened to answer.

🔎 The Problem

builder.Services.AddRateLimiter(options =>
{
    options.AddFixedWindowLimiter("api", opt =>
    {
        opt.PermitLimit = 100;
        opt.Window = TimeSpan.FromMinutes(1);
    });
});
// In-memory per-instance state: 3 replicas behind a load balancer each
// enforce their OWN 100-requests-per-minute window independently, so a
// client round-robined across all three can realistically send ~300
// requests/minute total before any single instance would reject one

✅ Fix: A Rate Limiter Resetting Its Window Too Early

  • Use a distributed rate limiter backed by a shared store (Redis-backed implementations are the common choice) whenever the app runs as more than one instance, so the window and count are shared rather than per-replica.
  • If sticky sessions are already part of your architecture for other reasons, confirm the load balancer is actually routing a given client consistently to the same instance — don’t rely on it as a rate-limiting strategy on its own.
  • Add a test that simulates multiple instances hitting the same limiter configuration independently, so the gap between “the limit works in a single-instance dev environment” and production is caught before it ships.

🚨 Why This Is Dangerous

  • A rate limit that silently multiplies by your replica count under load is exactly the kind of protection that looks like it’s working in every manual test and then fails precisely when the system is under enough real traffic to need it.

A rate limiter is only as global as the state it reads from — in-memory means local, and local means every replica gets its own private allowance.

— Backend Architect

Related posts:

.NET Core: Understand Scoped, Transient, and Singleton Services

.NET Core: Understand Scoped, Transient, and Singleton Services

.NET Core: Configure CORS for API Security

.NET Core: Configure CORS for API Security

Why Async Controllers Improve Throughput (Not Speed)

Why Async Controllers Improve Throughput (Not Speed)

Views: 8
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

Git: Fix a Rebase –onto Leaving Orphaned Commits Behind
C#: Fix a Primary Constructor Parameter Shadowed by a Field

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Read

  1. 01How to make theater mode the default for Youtube 1,079 views
  2. 02How to add default value for Entity Framework migrations for DateTime and Bool 996 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 995 views
  4. 04Get the First and Last Word from a String or Sentence in SQL 873 views
  5. 05How to select distinct rows in a datatable in C# 866 views
  6. 06How to enable, disable and check if Service Broker is enabled on a database in SQL Server 671 views
  7. 07Add Constraint to SQL Table to ensure email contains @ 629 views
  8. 08Average of all values in a column that are not zero in SQL 584 views
  9. 09How to use Map Mode for Vertical Scroll Mode in Visual Studio 561 views
Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
Back to top
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com