Skip to content

Search EricksonLopez.* Ecosystem

Type a library name, NuGet package ID, .NET type, or architectural concept to search across the portal.

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 RateLimitLease struct: RateLimitLease is a readonly record struct : IDisposable carrying IsAcquired, RemainingPermits, RetryAfter, ResetTime, Limit, and optional DisposeAction.
  • Five composable algorithms: FixedWindowRateLimiter, SlidingWindowRateLimiter, TokenBucketRateLimiter, ConcurrencyRateLimiter, and CompositeRateLimiter.
  • Fail-open / fail-closed middleware policy: RateLimitingMiddlewareOptions supports tenant/user-partitioned keys, ExcludedPathPrefixes (["/health"]), and configurable FailClosed behavior when Redis is unreachable.
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>)"]
Rate Limiting Acquire and Defensive Lockout FlowRequest partition key passes through DefensiveLockoutMiddleware and RateLimitingMiddleware to IRateLimiter.AcquireAsync, returning a disposable RateLimitLease or HTTP 429 Retry-After.
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>)"]

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 B
  • BCL_TokenBucket_AttemptAcquire: 15.9159 ns / 40 B
  • EricksonLopez_FixedWindow_AcquireAsync: 193.6843 ns / 184 B
  • EricksonLopez_SlidingWindow_AcquireAsync: 203.9667 ns / 184 B
  • EricksonLopez_TokenBucket_AcquireAsync: 208.0123 ns / 184 B