SmartRateLimiter.NET 1.0.0

dotnet add package SmartRateLimiter.NET --version 1.0.0
                    
NuGet\Install-Package SmartRateLimiter.NET -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SmartRateLimiter.NET" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SmartRateLimiter.NET" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="SmartRateLimiter.NET" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SmartRateLimiter.NET --version 1.0.0
                    
#r "nuget: SmartRateLimiter.NET, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SmartRateLimiter.NET@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SmartRateLimiter.NET&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=SmartRateLimiter.NET&version=1.0.0
                    
Install as a Cake Tool

๐Ÿš€ SmartRateLimiter.NET

A plug & play, production-ready rate limiting library for ASP.NET Core.

Supports multiple algorithms, storage strategies, and distributed systems.


โœจ Features

  • โšก Multiple algorithms:

    • Sliding Window (default)
    • Fixed Window
    • Token Bucket
  • ๐ŸŸข In-Memory support (fast, simple)

  • ๐Ÿ”ด Redis support (distributed systems)

  • ๐Ÿ”ฅ Hybrid mode (Memory + Redis + fallback)

  • ๐ŸŽฏ Attribute-based per-endpoint control

  • ๐Ÿงฉ Middleware integration

  • ๐Ÿ“„ Swagger UI integration

  • ๐Ÿง  Clean architecture (Strategy Pattern)


๐Ÿ“ฆ Installation

dotnet add package SmartRateLimiter.NET

โš™๏ธ Quick Start

Program.cs

builder.Services.AddSmartRateLimiter(options =>
{
    options.DefaultLimit = 5;
    options.DefaultWindowSeconds = 10;
});

app.UseSmartRateLimiter();

๐Ÿ” Storage Modes


๐ŸŸข In-Memory (Default)

builder.Services.AddSmartRateLimiter();

โœ” Fast โŒ Not shared across instances


๐Ÿ”ด Redis (Distributed)

builder.Services.AddSmartRateLimiterWithRedis("localhost:6379");

โœ” Shared across multiple instances โœ” Production ready


builder.Services.AddSmartRateLimiterHybrid("localhost:6379");

โœ” Fast (memory) โœ” Distributed (Redis) โœ” Resilient (fallback if Redis fails)


๐ŸŽฏ Usage (Per Endpoint)

[RateLimit(Type = RateLimitType.SlidingWindow, Limit = 5, WindowSeconds = 10)]
[HttpGet("users")]
public IActionResult GetUsers()
{
    return Ok();
}

๐Ÿ” Algorithms


Sliding Window

[RateLimit(Type = RateLimitType.SlidingWindow, Limit = 5, WindowSeconds = 10)]

Fixed Window

[RateLimit(Type = RateLimitType.FixedWindow, Limit = 10, WindowSeconds = 60)]

Token Bucket

[RateLimit(Type = RateLimitType.TokenBucket, Capacity = 10, RefillRate = 2, IntervalSeconds = 5)]

๐Ÿ“ค Response When Limit Exceeded

HTTP 429 Too Many Requests

๐Ÿงฑ Architecture

Client Request
      โ†“
RateLimiter Middleware
      โ†“
Strategy Resolver
      โ†“
Algorithm Strategy
      โ†“
Store (Memory / Redis / Hybrid)
      โ†“
Allow / Reject

๐Ÿงช Demo Project

A working demo is available in /demo folder.

Run:

cd demo/SmartRateLimiter.Demo
dotnet run

Open Swagger:

https://localhost:xxxx/swagger

โš™๏ธ Config-Based Mode Switching

{
  "RateLimiter": {
    "Mode": "Hybrid",
    "RedisConnection": "localhost:6379"
  }
}

๐Ÿ’ก Real Use Cases

  • ๐Ÿ” Login APIs (strict rate limiting)
  • ๐Ÿ›’ Product APIs (moderate limits)
  • ๐Ÿ’ณ Payment APIs (smooth burst handling)
  • ๐Ÿ“ก Public APIs (abuse protection)

๐Ÿ›  Tech Stack

  • .NET 8
  • ASP.NET Core Middleware
  • Redis (StackExchange.Redis)
  • Swagger (Swashbuckle)

๐Ÿ“ˆ Roadmap

  • Response headers (X-RateLimit-Remaining)
  • Retry-After header
  • Metrics & logging
  • Dashboard UI
  • API key-based rate limiting

๐Ÿค Contributing

Pull requests welcome.


๐Ÿ“œ License

MIT License

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 101 4/12/2026