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
                    
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="Hrithik.Security.Idempotency" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hrithik.Security.Idempotency" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Hrithik.Security.Idempotency" />
                    
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 Hrithik.Security.Idempotency --version 1.0.0
                    
#r "nuget: Hrithik.Security.Idempotency, 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 Hrithik.Security.Idempotency@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=Hrithik.Security.Idempotency&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Hrithik.Security.Idempotency&version=1.0.0
                    
Install as a Cake Tool

πŸ” 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:

Support is entirely optional and helps sustain ongoing development and maintenance.


This package is part of the Hrithik.Security ecosystem:

  • Hrithik.Security.ApiKeyManagement
    API key generation, storage, and scope-based authorization

  • Hrithik.Security.RequestSigning
    HMAC-based request signing for tamper-proof APIs

  • Hrithik.Security.ReplayProtection
    Short-window replay attack prevention

  • Hrithik.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 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.
  • 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