aj-geddes avatar

Idempotency Handling

This handles the tricky problem of ensuring operations don't run twice when requests get retried, which matters a lot for payments, order creation, or anything where duplicates cause real problems. The reference guides cover Redis-based storage, database implementations, and patterns modeled after Stripe's approach. You get middleware examples for Express and message queue handlers. The best practices are sensible: store the request body with the idempotency key so you can validate duplicates match, set TTLs so you're not storing this data forever, and use database constraints to handle concurrent requests atomically. If you're building any API that handles money or irreversible actions, you need something like this.

skills.sh installs
467
GitHub stars
379
last updated
Aug 21, 2026

Install

$ npx -y skills add aj-geddes/useful-ai-prompts --skill idempotency-handling --agent claude-code

Installs into .claude/skills of the current project.

Files

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);
  }

Sponsors

Details

Repository
github.com/aj-geddes/useful-ai-prompts
Categories
AI & Agent Building, Finance & Trading
First seen
Jun 3, 2026

More from aj-geddes/useful-ai-prompts

All 258
1aj-geddes avatarsession-managementaj-geddes/useful-ai-promptsImplement secure session management systems with JWT tokens, session storage, token refresh, logout handling, and CSRF protection. Use when managing user authen466skills.sh installs
2jwynia avatarsettlement-designjwynia/agent-skillsDesign cities, towns, and settlements for fictional worlds. Use when creating urban environments, mapping city districts, or when settlements need realistic lay466skills.sh installs
3jwynia avatarshared-worldjwynia/agent-skillsMaintain a wiki-style world bible for collaborative fiction. Use for long-running story worlds, shared universes, membership sites, or any fiction requiring per466skills.sh installs
4aj-geddes avatarquery-caching-strategiesaj-geddes/useful-ai-promptsImplement query caching strategies to improve performance. Use when setting up caching layers, configuring Redis, or optimizing database query response times.465skills.sh installs
5aj-geddes avatarrisk-assessmentaj-geddes/useful-ai-promptsIdentify, analyze, and prioritize project risks using qualitative and quantitative methods. Develop mitigation strategies to minimize impact and maximize projec465skills.sh installs
6n0an avatarswift-format-stylen0an/swift-formatstyle-agent-skillWrites and reviews Swift FormatStyle code, replacing legacy Formatter subclasses and C-style String(format:) with modern .formatted() APIs. Use when formatting 465skills.sh installs