- Home
- Skills
- APIs & Backend
- Idempotent API Design Auditor
Works with the AI Agents you already use
Idempotent API Design Auditor
Implement mission-critical idempotency in POST/PATCH APIs using Redis locks and atomic response caching.
$15
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
- Add the middleware to your
POST /paymentsroute definition. - Ensure your Redis environment variables are configured in
.env. - Verify that your frontend clients are generating and sending unique UUIDs in the
Idempotency-Keyheader.
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-KeyHTTP headers. - Conflict Handling manages concurrent in-flight duplicates by returning
409 Conflictstatuses. - 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
- Header Identification to extract the unique idempotency token from the incoming mutation request.
- Lock Acquisition via Redis to ensure only one process handles a specific key at a time.
- State Verification to check if a successful response for the key already exists in the cache.
- 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
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
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 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 installationorelevated privileges required.
File System Read/Write (strictly scoped to current project workspace `./`).
Permissions
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.