mcpField
I
idempotency-handling

idempotency-handling

github.com/aj-geddesDevelopment373463 installsUpdated 34w ago
Repository

About idempotency-handling

A development skill for implementing idempotent operations that return consistent results when repeated. It covers common retry scenarios and offers guidance for storing and validating requests and responses.

Key features

  1. 01Idempotency keys for mutations
  2. 02Request and response storage
  3. 03Request-body validation
  4. 04Concurrent request handling
  5. 05Duplicate response consistency
  6. 06Idempotency record cleanup

Use cases

  1. 01Preventing duplicate payment processing
  2. 02Handling retries on API endpoints
  3. 03Processing repeated webhooks or callbacks
  4. 04Avoiding duplicate message-queue operations

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill idempotency-handling

After installing, type/idempotency-handlingin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
database-based-idempotency.md
express-idempotency-middleware.md
message-queue-idempotency.md
stripe-style-idempotency.md
scripts/
validate-api.sh
templates/
api-scaffold.yaml

Details

From the project README

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

Comments

Markdown supported