Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
aj-geddes avatar

Idempotency Handling

  • 406 installs
  • 305 repo stars
  • Updated March 4, 2026
  • aj-geddes/useful-ai-prompts

idempotency-handling is an agent skill that designs idempotent API endpoints, payment flows, and webhook handlers for developers who must prevent duplicate charges and state corruption on retries.

About

idempotency-handling is an agent skill in aj-geddes/useful-ai-prompts for designing safe retry behavior in backend systems. The skill covers idempotent API endpoints, payment flows, and webhook handlers so duplicate client submits and network retries never double-charge or corrupt application state. Developers reach for idempotency-handling when integrating Stripe-like payments, webhook consumers, or write APIs that clients may retry after timeouts. The patterns focus on deterministic keys, deduplication, and state transitions rather than frontend routing or operational runbooks. Use it while building backend integrations that must stay correct under at-least-once delivery.

  • Idempotency keys
  • Safe client retries
  • Webhook deduplication
  • Conflict response codes
  • State dedup storage

Idempotency Handling by the numbers

  • 406 all-time installs (skills.sh)
  • Ranked #1,068 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill idempotency-handling

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs406
repo stars305
Last updatedMarch 4, 2026
Repositoryaj-geddes/useful-ai-prompts

How do you make payment APIs safe on retries?

Design idempotent API endpoints, payment flows, and webhook handlers so retries and duplicate client submits never double-charge or corrupt state.

Who is it for?

Backend developers building payment APIs, webhooks, or write endpoints that clients and gateways may retry after failures.

Skip if: Developers working on read-only endpoints, frontend routing, or tasks with no retry or duplicate-submit risk.

When should I use this skill?

Designing APIs, payments, or webhooks where retries, duplicate submits, or at-least-once delivery could double-charge or corrupt state.

What you get

Idempotent endpoint designs, payment flow safeguards, webhook deduplication patterns, and retry-safe state transition rules.

  • Idempotent API design
  • Payment retry safeguards
  • Webhook deduplication pattern

Files

SKILL.mdMarkdownGitHub ↗

Idempotency Handling

Table of Contents

Overview

Implement idempotency to ensure operations produce the same result regardless of how many times they're executed.

When to Use

  • Payment processing
  • API endpoints with retries
  • Webhooks and callbacks
  • Message queue consumers
  • Distributed transactions
  • Bank transfers
  • Order creation
  • Email sending
  • Resource creation

Quick Start

Minimal working example:

import express from "express";
import Redis from "ioredis";
import crypto from "crypto";

interface IdempotentRequest {
  key: string;
  status: "processing" | "completed" | "failed";
  response?: any;
  error?: string;
  createdAt: number;
  completedAt?: number;
}

class IdempotencyService {
  private redis: Redis;
  private ttl = 86400; // 24 hours

  constructor(redisUrl: string) {
    this.redis = new Redis(redisUrl);
  }

  async getRequest(key: string): Promise<IdempotentRequest | null> {
    const data = await this.redis.get(`idempotency:${key}`);
    return data ? JSON.parse(data) : null;
  }
// ... (see reference guides for full implementation)

Reference Guides

Detailed implementations in the references/ directory:

GuideContents
Express Idempotency MiddlewareExpress Idempotency Middleware
Database-Based IdempotencyDatabase-Based Idempotency
Stripe-Style IdempotencyStripe-Style Idempotency
Message Queue IdempotencyMessage Queue Idempotency

Best Practices

✅ DO

  • Require idempotency keys for mutations
  • Store request and response together
  • Set appropriate TTL for idempotency records
  • Validate request body matches stored request
  • Handle concurrent requests gracefully
  • Return same response for duplicate requests
  • Clean up old idempotency records
  • Use database constraints for atomicity

❌ DON'T

  • Apply idempotency to GET requests
  • Store idempotency data forever
  • Skip validation of request body
  • Use non-unique idempotency keys
  • Process same request concurrently
  • Change response for duplicate requests

Related skills

FAQ

What systems does idempotency-handling cover?

idempotency-handling covers idempotent API endpoints, payment flows, and webhook handlers. The skill targets retries and duplicate client submits that could otherwise double-charge customers or corrupt backend state.

When should idempotency-handling be invoked?

idempotency-handling should be invoked while designing backend write paths—especially payments and webhooks—where at-least-once delivery or client retries are expected. The skill focuses on deduplication and safe state transitions.

Backend & APIsbackendintegrations

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.