Hrithik.Security.Idempotency
1.0.0
dotnet add package Hrithik.Security.Idempotency --version 1.0.0
NuGet\Install-Package Hrithik.Security.Idempotency -Version 1.0.0
<PackageReference Include="Hrithik.Security.Idempotency" Version="1.0.0" />
<PackageVersion Include="Hrithik.Security.Idempotency" Version="1.0.0" />
<PackageReference Include="Hrithik.Security.Idempotency" />
paket add Hrithik.Security.Idempotency --version 1.0.0
#r "nuget: Hrithik.Security.Idempotency, 1.0.0"
#:package Hrithik.Security.Idempotency@1.0.0
#addin nuget:?package=Hrithik.Security.Idempotency&version=1.0.0
#tool nuget:?package=Hrithik.Security.Idempotency&version=1.0.0
π Hrithik.Security.Idempotency
Enterprise-grade idempotency for ASP.NET Core APIs
Hrithik.Security.Idempotency ensures exactly-once execution for HTTP operations by safely handling duplicate client requests using an Idempotency-Key header.
It is designed for payments, fintech, trading, order-processing, and retry-sensitive APIs, where repeated requests must never cause duplicate side effects.
β¨ Key Features
Header-based idempotency (Idempotency-Key)
Middleware-based (no changes to business logic)
Detects idempotency key reuse with modified requests
Request hashing (method + path + query + body)
Pluggable storage model (In-Memory, Redis, SQL)
API-agnostic and framework-aligned
Works with Minimal APIs and Controllers
π¦ Installation dotnet add package Hrithik.Security.Idempotency
π§ How It Works
Client sends a request with an Idempotency-Key header
The request is hashed using:
HTTP method
Request path
Query string
Request body
If the key is new, the request executes and the response is stored
If the key is reused:
Same request β stored response is replayed
Different request β request is rejected
This guarantees safe retries without duplicate execution.
π οΈ Minimal Setup 1οΈβ£ Register Services builder.Services.AddSingleton<IIdempotencyStore, InMemoryIdempotencyStore>(); builder.Services.AddIdempotency();
β οΈ The in-memory store is intended for development and testing only. Use a distributed store (Redis or SQL) in production environments.
2οΈβ£ Add Middleware app.UseIdempotency();
Thatβs it. No changes to your controllers or endpoints are required.
π§ͺ Example Request POST /transfer?amount=100 Idempotency-Key: 11111111-1111-1111-1111-111111111111
Behavior Scenario Result First request Executes business logic Duplicate request (same key + same data) Response replayed Key reused with different data Request rejected β Error Response (Recommended)
When a key is reused with different request data:
{ "error": "IDEMPOTENCY_KEY_REUSE", "message": "Idempotency key was reused with a different request payload." }
Suggested HTTP status code: 409 Conflict
π Security Design
Request hash includes method, path, query string, and body
Prevents tampering and duplicate side effects
Designed for retry-heavy and high-trust environments
π Optional Integrations
Hrithik.Security.Idempotency works independently but is commonly used alongside:
Request signing (tamper protection)
Replay protection (short-window duplicate blocking)
API key management (client isolation)
Rate limiting (abuse prevention)
These integrations are optional and not required for basic usage.
β οΈ Production Notes
Use a distributed idempotency store (Redis or SQL)
Ensure TTL cleanup to prevent unbounded growth
Add global exception handling for clean API responses
Avoid excessively long idempotency key retention windows
ποΈ Architecture Overview Client βββ Idempotency-Key β Idempotency Middleware βββ Hash request βββ Check store βββ Replay OR execute β Business Endpoint
π§βπ» Ideal Use Cases
Payments and transfers
Order creation APIs
Trading systems
Webhook receivers
Retry-safe POST / PUT endpoints
π License
MIT License
π€ Author
Hrithik Kalra
π§ Email: hrithikkalra11@gmail.com
If you find this package useful, consider supporting its development:
- β Buy Me a Coffee: https://www.buymeacoffee.com/alkylhalid9
- β€οΈ GitHub Sponsors: https://github.com/sponsors/hrithikalra
Support is entirely optional and helps sustain ongoing development and maintenance.
π Related Packages
This package is part of the Hrithik.Security ecosystem:
Hrithik.Security.ApiKeyManagement
API key generation, storage, and scope-based authorizationHrithik.Security.RequestSigning
HMAC-based request signing for tamper-proof APIsHrithik.Security.ReplayProtection
Short-window replay attack preventionHrithik.Security.RateLimiting
Flexible, API-keyβaware rate limiting for ASP.NET Core APIs
These packages are independent and can be used together or individually.
| Product | Versions 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. |
-
net8.0
- No dependencies.
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 | 126 | 2/2/2026 |