{
  "id": 10407602,
  "title": "Designing an Idempotent Payment API in ASP.NET Core",
  "url": "https://urgent.news/2026/09/28/designing-an-idempotent-payment-api-in-asp-net-core",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-28T09:01:43.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/developerimranahmed/designing-an-idempotent-payment-api-in-aspnet-core-1g3k"
  },
  "original_language": "en",
  "account": "Creating an Idempotent Payment API in ASP.NET Core is crucial for avoiding duplicate charges when clients retry requests due to network issues. In a recent project, the payment endpoint lacked a mechanism to check if a transaction had already been processed. If a client retried the request, the server would process the payment again, resulting in multiple charges. This is a common problem in distributed systems where failures are common.\n\nTo solve this, an Idempotency-Key header was introduced. Each unique request includes a client-generated key. The server stores this key along with its response in a SQL Server database. When the same key is received again, the server returns the stored response without reprocessing the payment. This approach ensures idempotency, meaning the same request can be made multiple times without changing the result beyond the initial application.\n\nIn ASP.NET Core, the implementation involves creating a PaymentsController with an HTTP POST action. The action first checks for an existing Idempotency-Key in the database. If a matching key is found, it returns the stored response, effectively handling the retry. If no key is found, the payment is processed, and the result is stored in the database along with the key. The entire operation is wrapped in a database transaction to prevent race conditions, ensuring that only one request can insert the key at a time.\n\nThis solution addresses the core problem of duplicate charges by ensuring that retries do not cause unintended side effects. The Idempotency-Key pattern, combined with persistent storage and transaction handling, provides a reliable method for making APIs safe against retries. By adopting this approach, developers can create robust payment APIs that are user-friendly and prevent major issues like duplicate charges.",
  "summary": "Designing an Idempotent Payment API in ASP.NET Core Introduction When building APIs that handle payments or any mutable operations, ensuring retries don't cause unintended side effects is vital. This case study explores a practical pattern for idempotency in ASP.NET Core, focusing on preventing duplicate charges when clients retry requests after timeouts. The Problem: Duplicate Charges on Retries…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}