Skip to content
secondsky avatar

Idempotency Handling

Reusable idempotency patterns for API mutations, using Redis caching or database constraints to block duplicate processing.

CCM score
58 of 100
skills.sh installs
424
GitHub stars
257
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers idempotency keys for API mutations, with a Redis middleware variant and a PostgreSQL-backed variant for payment flows
  • Includes a processing, completed, and failed status lifecycle plus a SHA-256 request hash that rejects reused keys with different payloads
  • Enforces 24-hour key expiry and uses atomic INSERT ... ON CONFLICT so only one concurrent request executes the operation
  • Designed for payment processing, order creation, webhook handling, and email sending, with TTL cleanup jobs in SQL, Node.js, and Python

Install

$ npx -y skills add secondsky/claude-skills --skill idempotency-handling -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

Idempotency Handling

Ensure operations produce identical results regardless of execution count.

Idempotency Key Pattern

const redis = require('redis');
const client = redis.createClient();

async function idempotencyMiddleware(req, res, next) {
  const key = req.headers['idempotency-key'];
  if (!key) return next();

  const cached = await client.get(`idempotency:${key}`);
  if (cached) {
    const { status, body } = JSON.parse(cached);
    return res.status(status).json(body);
  }

  // Store original send
  const originalSend = res.json.bind(res);
  res.json = async (body) => {
    await client.setEx(
      `idempotency:${key}`,
      86400, // 24 hours
      JSON.stringify({ status: res.statusCode, body })
    );
    return originalSend(body);
  };

  next();
}

Database-Backed Idempotency

CREATE TABLE idempotency_keys (
  key VARCHAR(255) PRIMARY KEY,
  request_hash VARCHAR(64) NOT NULL,
  response JSONB,
  status VARCHAR(20) DEFAULT 'processing',
  created_at TIMESTAMP DEFAULT NOW(),
  expires_at TIMESTAMP DEFAULT NOW() + INTERVAL '24 hours'
);

CREATE INDEX idx_idempotency_expires ON idempotency_keys(expires_at);

Details

Repository
github.com/secondsky/claude-skills
Categories
Backend & APIs, Databases
First seen
Jun 3, 2026

Questions

What does the idempotency-handling skill do?

The idempotency-handling skill makes API operations produce identical results no matter how many times they run. It covers idempotency keys with Redis caching, database-backed key storage with constraints, and cleanup of expired keys.

When should I use idempotency-handling?

Use idempotency-handling for payment systems, order creation, webhook handling, email sending, and safe retries. It also helps when you run into duplicate processing, race conditions, or idempotency key expiry errors.

Where does idempotency-handling sit in the Backend & APIs category?

idempotency-handling is listed in the Backend & APIs category alongside entra-app-registration, neon, firebase-basics, firebase-auth-basics and workers-best-practices. Its focus on duplicate-safe mutations sets it apart from those skills.

How do I install the idempotency-handling skill?

Run npx -y skills add secondsky/claude-skills --skill idempotency-handling -y in your project. The idempotency-handling skill then lets your agent add idempotency keys, Redis caching and database constraints to your API.

More from secondsky/claude-skills

All 116

Similar to Idempotency Handling

More Backend & APIs