EricksonLopez.RateLimiting Overview
EricksonLopez.RateLimiting (1.0.0 on NuGet, L2) provides composable in-memory and Redis-backed rate limiting algorithms, defensive lockout protection, ASP.NET Core middleware, and EricksonLopez.Result integration.
- Zero-allocation
RateLimitLeasestruct:RateLimitLeaseis areadonly record struct : IDisposablecarryingIsAcquired,RemainingPermits,RetryAfter,ResetTime,Limit, and optionalDisposeAction. - Five composable algorithms:
FixedWindowRateLimiter,SlidingWindowRateLimiter,TokenBucketRateLimiter,ConcurrencyRateLimiter, andCompositeRateLimiter. - Fail-open / fail-closed middleware policy:
RateLimitingMiddlewareOptionssupports tenant/user-partitioned keys,ExcludedPathPrefixes(["/health"]), and configurableFailClosedbehavior when Redis is unreachable.
Rendering diagram…
flowchart LR Req["HTTP / Service Request"] --> Lockout["DefensiveLockoutMiddleware"] Lockout --> Lim["IRateLimiter.AcquireAsync(key, permits)"] Lim -- IsAcquired --> Lease["using RateLimitLease -> Execute"] Lim -- Rejected --> Reject["429 / Retry-After (Result<RateLimitLease>)"]
View accessible text summary and structure
Request partition key passes through DefensiveLockoutMiddleware and RateLimitingMiddleware to IRateLimiter.AcquireAsync, returning a disposable RateLimitLease or HTTP 429 Retry-After.
flowchart LR
Req["HTTP / Service Request"] --> Lockout["DefensiveLockoutMiddleware"]
Lockout --> Lim["IRateLimiter.AcquireAsync(key, permits)"]
Lim -- IsAcquired --> Lease["using RateLimitLease -> Execute"]
Lim -- Rejected --> Reject["429 / Retry-After (Result<RateLimitLease>)"]Package Roster & Native AOT Status (3 / 3 Published)
Section titled “Package Roster & Native AOT Status (3 / 3 Published)”All 3 packages are published at 1.0.0 on NuGet (461 total downloads; localVersion: 2.0.0 unreleased on disk), target net8.0;net9.0;net10.0, and declare Full AOT (IsAotCompatible=true, EnableTrimAnalyzer=true):
| Package | NuGet (1.0.0) |
Local HEAD | AOT Status | Role |
|---|---|---|---|---|
EricksonLopez.RateLimiting |
Published (181 dl) |
2.0.0 |
Full |
Core IRateLimiter, 5 limiter algorithms, RateLimiterPolicyBuilder, InMemoryDefensiveLockoutStore |
EricksonLopez.RateLimiting.AspNetCore |
Published (132 dl) |
2.0.0 |
Full |
RateLimitingMiddleware, DefensiveLockoutMiddleware, [EnableRateLimiting], AddRateLimiting |
EricksonLopez.RateLimiting.Redis |
Published (148 dl) |
2.0.0 |
Full |
RedisSlidingWindowRateLimiter, RedisTokenBucketRateLimiter, RedisDefensiveLockoutStore |
Measured directly from BenchmarkDotNet.Artifacts (5 measured rows, 0 na_error rows) in RateLimiterHotPathBenchmarks on .NET 10.0.11 X64 RyuJIT x86-64-v4 (no NativeAOT reports):
EricksonLopez_RateLimitLease_Struct_ZeroAllocation: 0 ns / 0 BBCL_TokenBucket_AttemptAcquire: 15.9159 ns / 40 BEricksonLopez_FixedWindow_AcquireAsync: 193.6843 ns / 184 BEricksonLopez_SlidingWindow_AcquireAsync: 203.9667 ns / 184 BEricksonLopez_TokenBucket_AcquireAsync: 208.0123 ns / 184 B