Idempotency.Net 1.0.1

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

Idempotency.Net

build

Idempotency.Net is a lean library for implementing idempotent operations in .NET applications. It ensures safe retries, request deduplication, and consistent execution of APIs, background jobs, and message handlers.

It integrates with ASP.NET Core and supports multiple storage providers through a pluggable persistence model, making it suitable for high-reliability and distributed systems.

Installation

Install the core package:

dotnet add package Idempotency.Net

Install ASP.NET Core integration:

dotnet add package Idempotency.Net.AspNetCore

Install a persistence provider:

dotnet add package Idempotency.Net.Redis
dotnet add package Idempotency.Net.PostgreSql

Quick Example

Clients can provide an idempotency key using the X-Idempotency-Key header.
Requests with the same key will only be executed once.

curl -X POST http://localhost:5000/orders \
  -H "Content-Type: application/json" \
  -H "X-Idempotency-Key: 8f3b2c1a-6f41-4a63-b5fa-3e5e0b3c7c21" \
  -d '{
        "productId": "123",
        "quantity": 1
      }'

If the same request is retried with the same X-Idempotency-Key, the previously stored response will be returned instead of executing the operation again.

Register Idempotency in your application:

When using provider-specific packages, import the corresponding namespace:

using Idempotency.Net.PostgreSql;
using Idempotency.Net.Redis;

Configure Postgres

builder.Services
    .AddIdempotency(options =>
    {
        options.HeaderName = "X-Idempotency-Key";
        options.Expiration = TimeSpan.FromHours(12);
    })
    .UsePostgreSql(options =>
    {
        options.ConnectionString = builder.Configuration.GetConnectionString("PostgreSql");
        options.Schema = "idempotency";
        options.TableName = "requests";
        options.EnableAutoCreateTable = true;
        options.UseAdvisoryLocks = true;
        options.CommandTimeout = TimeSpan.FromSeconds(15);
        options.CleanupBatchSize = 2_000;
    });

Or configure Redis:

builder.Services
    .AddIdempotency(options =>
    {
        options.HeaderName = "X-Idempotency-Key";
        options.Expiration = TimeSpan.FromMinutes(30);
    })
    .UseRedis(options =>
    {
        options.ConnectionString = builder.Configuration.GetConnectionString("Redis");
        options.Configuration = "localhost:6379,allowAdmin=true,ssl=false";
        options.InstanceName = "idempotency";
        options.Database = 2;
        options.KeyPrefix = "orders:";
        options.ConnectTimeout = TimeSpan.FromSeconds(3);
        options.SyncTimeout = TimeSpan.FromSeconds(2);
        options.AbortOnConnectFail = false;
    });

ASP.NET Core Controllers

Use the [Idempotent] attribute to protect operations:

[Idempotent]
[HttpPost("/orders")]
public async Task<IActionResult> CreateOrder(CreateOrderRequest request)
{
    var order = await _service.CreateAsync(request);
    return Ok(order);
}

Minimal APIs

Idempotency can also be applied to Minimal APIs:

app.MapPost("/orders", async (CreateOrderRequest request, IOrderService service) =>
{
    var order = await service.CreateAsync(request);
    return Results.Ok(order);
})
.WithIdempotency();

Dig Deeper

Runnable examples are available in the examples folder containing more details:

  • examples/DemoMinimalApi
  • examples/DemoControllerApi
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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 (3)

Showing the top 3 NuGet packages that depend on Idempotency.Net:

Package Downloads
Idempotency.Net.AspNetCore

ASP.NET Core integration for idempotent endpoints with attributes and minimal API filters.

Idempotency.Net.Redis

Redis persistence provider for Idempotency, enabling distributed request deduplication.

Idempotency.Net.PostgreSql

PostgreSQL persistence provider for Idempotency, with table management and advisory lock support.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 139 3/15/2026
1.0.0 135 3/12/2026
0.3.0 136 3/11/2026
0.2.0 134 3/11/2026
0.1.0 137 3/11/2026