Idempotency Handling

Idempotency Handling

Guides an AI agent to implement idempotency keys so API calls, payments, webhooks and queue consumers can be retried safely without duplicate effects.

Skill files7 files

references/

scripts/

templates/

SKILL.md100 lines
1
---
2
name: idempotency-handling
3
description: >
4
Implement idempotency keys and handling to ensure operations can be safely
5
retried without duplicate effects. Use when building payment systems, APIs
6
with retries, or distributed transactions.
7
---
8
9
# Idempotency Handling
10
11
## Table of Contents
12
13
- [Overview](#overview)
14
- [When to Use](#when-to-use)
15
- [Quick Start](#quick-start)
16
- [Reference Guides](#reference-guides)
17
- [Best Practices](#best-practices)
18
19
## Overview
20
21
Implement idempotency to ensure operations produce the same result regardless of how many times they're executed.
22
23
## When to Use
24
25
- Payment processing
26
- API endpoints with retries
27
- Webhooks and callbacks
28
- Message queue consumers
29
- Distributed transactions
30
- Bank transfers
31
- Order creation
32
- Email sending
33
- Resource creation
34
35
## Quick Start
36
37
Minimal working example:
38
39
```typescript
40
import express from "express";
41
import Redis from "ioredis";
42
import crypto from "crypto";
43
44
interface IdempotentRequest {
45
key: string;
46
status: "processing" | "completed" | "failed";
47
response?: any;
48
error?: string;
49
createdAt: number;
50
completedAt?: number;
51
}
52
53
class IdempotencyService {
54
private redis: Redis;
55
private ttl = 86400; // 24 hours
56
57
constructor(redisUrl: string) {
58
this.redis = new Redis(redisUrl);
59
}
60
61
async getRequest(key: string): Promise<IdempotentRequest | null> {
62
const data = await this.redis.get(`idempotency:${key}`);
63
return data ? JSON.parse(data) : null;
64
}
65
// ... (see reference guides for full implementation)
66
```
67
68
## Reference Guides
69
70
Detailed implementations in the `references/` directory:
71
72
| Guide | Contents |
73
|---|---|
74
| [Express Idempotency Middleware](references/express-idempotency-middleware.md) | Express Idempotency Middleware |
75
| [Database-Based Idempotency](references/database-based-idempotency.md) | Database-Based Idempotency |
76
| [Stripe-Style Idempotency](references/stripe-style-idempotency.md) | Stripe-Style Idempotency |
77
| [Message Queue Idempotency](references/message-queue-idempotency.md) | Message Queue Idempotency |
78
79
## Best Practices
80
81
### ✅ DO
82
83
- Require idempotency keys for mutations
84
- Store request and response together
85
- Set appropriate TTL for idempotency records
86
- Validate request body matches stored request
87
- Handle concurrent requests gracefully
88
- Return same response for duplicate requests
89
- Clean up old idempotency records
90
- Use database constraints for atomicity
91
92
### ❌ DON'T
93
94
- Apply idempotency to GET requests
95
- Store idempotency data forever
96
- Skip validation of request body
97
- Use non-unique idempotency keys
98
- Process same request concurrently
99
- Change response for duplicate requests
100

© AJ Geddes · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 13,916 prompts

More by @OpenSourceBuffGuy

See all
Pirate chef and parrot thief in galley prompt image

Pirate chef and parrot thief in galley

Generates a 30-second Pixar-style 3D comedy short with food ASMR, where a pirate chef keeps catching a parrot stealing ingredients in a lantern-lit ship galley.

video-prompt, seedance, timed-beats, multi-shot, animation, pixar-style, 3d-render, asmr, comedy, humorous, family-friendly, cinematic, character-consistency, cozy, close-up, wide-shot, slow-motion, short-film, animals, camera-movement, for-filmmakers, long-form

Crying woman in dim room, tears streaming prompt image

Crying woman in dim room, tears streaming

Generates a 5-second fixed close-up film shot of a woman sobbing and speaking one tearful line in a dim room, with strict lip-sync and sound rules.

video-prompt, wan, lip-sync, timed-beats, single-take, close-up, film-grain, cinematic, widescreen, short-film, woman, moody, dramatic-lighting, soft-lighting, negative-prompt, guardrails, structured-output, photorealistic, china, for-filmmakers, quick

Photo to hand-drawn chibi doodle prompt image

Photo to hand-drawn chibi doodle

Transforms an uploaded photo of a person into a cute hand-drawn doodle character with loose ink lines, light crayon colour and a big head.

image-prompt, reference-image, style-transfer, doodle, chibi, sketch, ink-drawing, illustration, cozy, whimsical, white-background, negative-space, storybook, character-design, minimalist, gpt-image, portrait, fashion, avatar, face-reference

Reviews

Loading reviews…

Discussion

Loading comments…