Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    Idempotent API Design Auditor

    1

    Implement mission-critical idempotency in POST/PATCH APIs using Redis locks and atomic response caching.

    $15

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    Idempotent API Design Auditor

    Idempotent API Design Auditor

    Example session with this skill installed

    Create a TypeScript Express middleware to handle idempotency for a payment endpoint using Redis. It needs to handle the Idempotency-Key header and prevent race conditions.

    • Read your context and instructions
    • Compiled the idempotent api design

    I have generated a production-ready TypeScript middleware for Express that implements atomic idempotency using Redis. This implementation handles header extraction, distributed locking, and cached response re-delivery.

    Idempotency Middleware Implementation

    import { Request, Response, NextFunction } from 'express';
    import Redis from 'ioredis';
    
    const redis = new Redis(process.env.REDIS_URL);
    const CACHE_TTL = 86400; // 24 hours
    
    export const idempotencyMiddleware = async (req: Request, res: Response, next: NextFunction) => {
      const idempotencyKey = req.header('Idempotency-Key');
    
      if (!idempotencyKey) {
        return next();
      }
    
      const lockKey = `lock:idempotency:${idempotencyKey}`;
      const cacheKey = `cache:idempotency:${idempotencyKey}`;
    
      try {
        // 1. Check for existing cached response
        const cachedResponse = await redis.get(cacheKey);
        if (cachedResponse) {
          const { status, body } = JSON.parse(cachedResponse);
          return res.status(status).json(body);
        }
    
        // 2. Attempt to acquire atomic lock (NX = Only if not exists, EX = TTL)
        const acquired = await redis.set(lockKey, 'in-progress', 'NX', 'EX', 60);
        if (!acquired) {
          return res.status(409).json({ error: 'Concurrent request in progress' });
        }
    
        // 3. Wrap res.json to capture and cache the response
        const originalJson = res.json.bind(res);
        res.json = (body: any) => {
          const responseData = { status: res.statusCode, body };
          
          // Save response and release lock atomically
          redis.pipeline()
            .set(cacheKey, JSON.stringify(responseData), 'EX', CACHE_TTL)
            .del(lockKey)
            .exec();
    
          return originalJson(body);
        };
    
        next();
      } catch (error) {
        console.error('Idempotency error:', error);
        next();
      }
    };
    

    Next steps

    1. Add the middleware to your POST /payments route definition.
    2. Ensure your Redis environment variables are configured in .env.
    3. Verify that your frontend clients are generating and sending unique UUIDs in the Idempotency-Key header.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Distributed systems fail, and when they do, your payment or mutation APIs risk duplicate executions that corrupt data. This skill provides the logic and middleware necessary to implement strict idempotency for mission-critical endpoints.

    What it does

    • Atomic Locking prevents race conditions by acquiring distributed Redis locks before processing requests.
    • Key Extraction identifies unique request identifiers from Idempotency-Key HTTP headers.
    • Conflict Handling manages concurrent in-flight duplicates by returning 409 Conflict statuses.
    • Response Caching stores final payloads and status codes atomically to ensure consistent re-delivery.
    • TTL Management configures appropriate time-to-live settings for cached responses to maintain storage efficiency.

    How it works

    1. Header Identification to extract the unique idempotency token from the incoming mutation request.
    2. Lock Acquisition via Redis to ensure only one process handles a specific key at a time.
    3. State Verification to check if a successful response for the key already exists in the cache.
    4. Execution and Persistence to process the business logic and atomically save the response for future duplicate calls.

    Frameworks & tools

    The skill generates production-grade TypeScript middleware designed for Node.js environments using Redis for atomic operations and distributed locking.

    Why this beats prompting it yourself

    Generic prompts often miss edge cases like race conditions between lock acquisition and response caching. This skill uses a deterministic workflow specifically modeled for financial transaction reliability and distributed state management.

    Use cases

    • Payment Processing to prevent double-charging users during network timeouts.
    • Order Creation ensuring a single checkout attempt does not create multiple database entries.
    • Resource Mutation protecting PATCH updates from redundant side effects.

    Known limitations

    Outputs are focused on TypeScript and Redis environments. Requires an active Redis instance for distributed locking to function.

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for APIs & Backend.

    Requires TypeScript and Redis. Designed for POST/PATCH mutation APIs only.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 3 days ago

    Software
    Zero global installation
    orelevated privileges required.

    File System Read/Write (strictly scoped to current project workspace `./`).

    Permissions

    Read Files

    Target Use Cases: - Design an idempotency middleware with Redis for payment APIs. - Prevent duplicate payment submissions using Idempotency-Key header. - Audit API mutation endpoints for idempotency compliance.

    Listed3 days ago

    What's inside

    Frequently Asked Questions

    This skill prevents duplicate transactions, such as double-charging a customer or creating redundant orders, by implementing a strict 'exactly-once' execution pattern using Redis-backed distributed locks.

    The skill is optimized for AI agents capable of generating backend code and is compatible with any Node.js/TypeScript environment that has access to a Redis instance.

    You will receive production-ready TypeScript middleware logic, Redis locking scripts, and a configuration guide for implementing atomic response caching in your existing API architecture.

    Unlike basic prompts, this skill accounts for the 'race condition window'—the micro-moment between a request arriving and the response being stored—ensuring that concurrent duplicate requests are handled safely.

    Yes, the logic allows for configurable TTL (Time-to-Live) settings, enabling you to define how long an idempotency key remains valid based on your specific business requirements.

    Setup requires an active Redis instance; the skill provides the middleware logic, but you will need to provide the Redis connection strings and ensure your environment supports TypeScript.

    New in APIs & Backend