{"id":25232138,"url":"https://github.com/mreshboboyev/api-rate-limiter","last_synced_at":"2026-05-05T07:31:12.591Z","repository":{"id":275407490,"uuid":"925980348","full_name":"MrEshboboyev/api-rate-limiter","owner":"MrEshboboyev","description":"A robust and scalable API Rate Limiter implementation in .NET Core, supporting 4 algorithms (Fixed Window, Sliding Window, Token Bucket, Concurrency) with IP-based rate limiting. Built using Clean Architecture and integrated with Redis for distributed environments.","archived":false,"fork":false,"pushed_at":"2025-11-08T18:30:35.000Z","size":47,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-08T20:23:29.405Z","etag":null,"topics":["api-security","clean-architecture","concurrency","fixed-window","ip-based-rate-limiting","middleware","rate-limiting","redis","security","sliding-window","throttling","token-bucket"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MrEshboboyev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-02-02T08:33:11.000Z","updated_at":"2025-11-08T18:30:40.000Z","dependencies_parsed_at":"2025-02-02T10:23:40.158Z","dependency_job_id":"834f97a5-0bfd-44dd-854f-b2f3588cc01f","html_url":"https://github.com/MrEshboboyev/api-rate-limiter","commit_stats":null,"previous_names":["mreshboboyev/api-rate-limiter"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MrEshboboyev/api-rate-limiter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrEshboboyev%2Fapi-rate-limiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrEshboboyev%2Fapi-rate-limiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrEshboboyev%2Fapi-rate-limiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrEshboboyev%2Fapi-rate-limiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MrEshboboyev","download_url":"https://codeload.github.com/MrEshboboyev/api-rate-limiter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrEshboboyev%2Fapi-rate-limiter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32640533,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-04T10:08:07.713Z","status":"online","status_checked_at":"2026-05-05T02:00:06.033Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-security","clean-architecture","concurrency","fixed-window","ip-based-rate-limiting","middleware","rate-limiting","redis","security","sliding-window","throttling","token-bucket"],"created_at":"2025-02-11T12:55:19.448Z","updated_at":"2026-05-05T07:31:12.586Z","avatar_url":"https://github.com/MrEshboboyev.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🚀 API Rate Limiter - .NET 9\n\n![.NET 9](https://img.shields.io/badge/.NET%209-%F0%9F%92%AA-blue)\n![Redis](https://img.shields.io/badge/Redis-%F0%9F%93%9A-red)\n![Clean Architecture](https://img.shields.io/badge/Clean%20Architecture-%F0%9F%9A%80-green)\n![Rate Limiting](https://img.shields.io/badge/Rate%20Limiting-%F0%9F%94%92-yellow)\n\nA powerful and scalable **API Rate Limiter** built with **.NET 9**, supporting multiple rate-limiting algorithms (**Fixed Window, Sliding Window, Token Bucket, Concurrency**) with **IP-based rate limiting**. Designed using **Clean Architecture** and integrated with **Redis** for distributed environments.\n\n---\n\n## 🌟 Features\n\n✅ **Multiple Rate-Limiting Algorithms**:\n   - **Fixed Window** 🕒 – Limits requests per fixed time window.\n   - **Sliding Window** 🔄 – Smooths request spikes with a rolling window.\n   - **Token Bucket** 🪙 – Allows burstable traffic via token-based management.\n   - **Concurrency** 🔗 – Restricts simultaneous client connections.\n\n✅ **IP-Based Rate Limiting** 📡 – Ensures fair request distribution across users.\n✅ **Redis Integration** 🛢️ – Enables scalable, distributed rate limiting.\n✅ **Clean Architecture** 🏗️ – Layered design following **best practices**.\n✅ **Fully Configurable** 🔧 – Manage rate limits in `appsettings.json`.\n\n---\n\n## 🛠️ Technologies Used\n\n| Technology  | Purpose  |\n|-------------|----------|\n| **.NET 9** | Core framework |\n| **Redis** | Distributed caching \u0026 rate limiting |\n| **StackExchange.Redis** | Redis client for .NET |\n| **MediatR** | CQRS pattern implementation |\n| **Serilog** | Logging |\n| **xUnit** | Unit testing framework |\n| **Moq** | Mocking for unit tests |\n\n---\n\n## 🏗️ Clean Architecture Overview\n\n📌 **This project follows Clean Architecture principles:**\n\n```\n📂 src/\n ├── 📁 App             # Runnable and installers located web api\n ├── 📁 Domain          # Business logic \u0026 entities\n ├── 📁 Application     # Use cases, handlers, services\n ├── 📁 Infrastructure  # Redis integration \u0026 rate-limiting logic\n ├── 📁 Persistence     # EF Core integration \u0026 implementations\n ├── 📁 Presentation    # API controllers \u0026 contracts\n```\n\n### ✨ Benefits of Clean Architecture\n- **Separation of Concerns** – Organized and maintainable code.\n- **Scalability** – Easily extendable for new features.\n- **Testability** – Isolated business logic for robust unit tests.\n\n---\n\n## ⚡ How It Works\n\n### **1️⃣ Fixed Window Algorithm**\n- Restricts requests within a fixed time period.\n- Example: `100 requests per minute`.\n\n### **2️⃣ Sliding Window Algorithm**\n- Maintains a rolling window to smooth traffic bursts.\n- Example: **Consider last `60 seconds` instead of resetting counters**.\n\n### **3️⃣ Token Bucket Algorithm**\n- Allows controlled bursts of traffic.\n- Example: **Users get `100 tokens`, refilling at `10/sec`**.\n\n### **4️⃣ Concurrency Algorithm**\n- Limits the number of simultaneous API requests.\n- Example: `Max 10 concurrent users`.\n\n### **5️⃣ IP-Based Rate Limiting**\n- Identifies and restricts request flow per IP address.\n- Ensures fair resource allocation across users.\n\n---\n\n## 🚀 Getting Started\n\n### 📝 Prerequisites\n\n✅ [.NET 9 SDK](https://dotnet.microsoft.com/download/dotnet/9.0)  \n✅ [Redis](https://redis.io/download)  \n✅ [Visual Studio Code](https://code.visualstudio.com/)  \n✅ [Postman](https://www.postman.com/) (for API testing)\n\n### 🔧 Installation \u0026 Setup\n\n#### 1️⃣ Clone the Repository\n```sh\n git clone https://github.com/MrEshboboyev/api-rate-limiter.git\n cd src\n```\n\n#### 2️⃣ Install Dependencies\n```sh\n dotnet restore\n```\n\n#### 3️⃣ Run Redis in Docker\n```sh\n docker run -d -p 6379:6379 redis\n```\n\n#### 4️⃣ Run the Application\n```sh\n dotnet run --project src/App\n```\n\n---\n\n## 🔧 Configuration\n\nModify `appsettings.json` to configure rate limits:\n\n```json\n{\n  \"RateLimitSettings\": {\n    \"FixedWindow\": {\n      \"PermitLimit\": 100,\n      \"WindowInSeconds\": 60\n    },\n    \"SlidingWindow\": {\n      \"PermitLimit\": 100,\n      \"WindowInSeconds\": 60\n    },\n    \"TokenBucket\": {\n      \"BucketSize\": 100,\n      \"RefillRate\": 10\n    },\n    \"Concurrency\": {\n      \"MaxConcurrentRequests\": 10\n    }\n  }\n}\n```\n\n---\n\n## 📡 API Endpoints\n\n| Method | Endpoint | Description |\n|--------|---------|-------------|\n| **GET** | `/api/rate-limit/get-random` | Enabled endpoint for rate limiting |\n| **POST** | `/api/rate-limit/get-random-two` | Disabled endpoint for rate limiting |\n\n---\n\n## 🧪 Testing\n\n### 🔍 Unit Tests\nRun tests to validate the functionality:\n```sh\n dotnet test\n```\n\n### 🌐 API Testing (Postman/cURL)\nSend multiple requests to trigger rate limiting:\n```sh\n curl -X GET http://localhost:5000/api/rate-limit/test\n```\n✅ If rate limit is exceeded, you’ll get **429 Too Many Requests**.\n\n---\n\n## 🤝 Contributing\n\nContributions are **welcome!** 🎉 If you find any issues or have suggestions, feel free to **open an issue** or **submit a pull request**.\n\n---\n\n## 📜 License\n\nThis project is **MIT Licensed**. See the [LICENSE](LICENSE) file for details.\n\n---\n\n## 🎉 Acknowledgments\n\nSpecial thanks to:\n- The **.NET** and **Redis** communities for excellent tools.\n- Clean Architecture \u0026 Domain-Driven Design inspirations.\n\n---\n\n## ✉️ Contact\n\n📬 **GitHub**: [MrEshboboyev](https://github.com/MrEshboboyev)  \n📬 **Email**: mreshboboyev@gmail.com\n\n---\n\n⭐ **Star this repository** if you found it helpful! 🚀\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmreshboboyev%2Fapi-rate-limiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmreshboboyev%2Fapi-rate-limiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmreshboboyev%2Fapi-rate-limiter/lists"}