idempotency-handling
支払い処理やAPIなど、同じ処理が重複して実行されないように、リトライ(再試行)しても安全な仕組みを実装し、システム全体の信頼性を高めるSkill。
📜 元の英語説明(参考)
Implement idempotency keys and handling to ensure operations can be safely retried without duplicate effects. Use when building payment systems, APIs with retries, or distributed transactions.
🇯🇵 日本人クリエイター向け解説
支払い処理やAPIなど、同じ処理が重複して実行されないように、リトライ(再試行)しても安全な仕組みを実装し、システム全体の信頼性を高めるSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o idempotency-handling.zip https://jpskill.com/download/21444.zip && unzip -o idempotency-handling.zip && rm idempotency-handling.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/21444.zip -OutFile "$d\idempotency-handling.zip"; Expand-Archive "$d\idempotency-handling.zip" -DestinationPath $d -Force; ri "$d\idempotency-handling.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
idempotency-handling.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
idempotency-handlingフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 6
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
冪等性の取り扱い
目次
概要
操作が何度実行されても同じ結果を生成するように、冪等性を実装します。
使用場面
- 決済処理
- リトライを伴うAPIエンドポイント
- Webhookとコールバック
- メッセージキューのコンシューマー
- 分散トランザクション
- 銀行振込
- 注文作成
- メール送信
- リソース作成
クイックスタート
最小限の動作例:
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);
}
async getRequest(key: string): Promise<IdempotentRequest | null> {
const data = await this.redis.get(`idempotency:${key}`);
return data ? JSON.parse(data) : null;
}
// ... (完全な実装についてはリファレンスガイドを参照してください)
リファレンスガイド
references/ ディレクトリ内の詳細な実装:
| ガイド | 内容 |
|---|---|
| Express Idempotency Middleware | Express Idempotency Middleware |
| Database-Based Idempotency | データベースベースの冪等性 |
| Stripe-Style Idempotency | Stripeスタイルの冪等性 |
| Message Queue Idempotency | メッセージキューの冪等性 |
ベストプラクティス
✅ 実施すべきこと
- ミューテーションには冪等性キーを必須とする
- リクエストとレスポンスを一緒に保存する
- 冪等性レコードに適切なTTLを設定する
- リクエストボディが保存されたリクエストと一致するか検証する
- 同時リクエストを適切に処理する
- 重複するリクエストに対しては同じレスポンスを返す
- 古い冪等性レコードをクリーンアップする
- アトミック性のためにデータベース制約を使用する
❌ 実施すべきでないこと
- GETリクエストに冪等性を適用する
- 冪等性データを永続的に保存する
- リクエストボディの検証をスキップする
- 一意でない冪等性キーを使用する
- 同じリクエストを同時に処理する
- 重複するリクエストに対してレスポンスを変更する
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
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);
}
async getRequest(key: string): Promise<IdempotentRequest | null> {
const data = await this.redis.get(`idempotency:${key}`);
return data ? JSON.parse(data) : null;
}
// ... (see reference guides for full implementation)
Reference Guides
Detailed implementations in the references/ directory:
| Guide | Contents |
|---|---|
| Express Idempotency Middleware | Express Idempotency Middleware |
| Database-Based Idempotency | Database-Based Idempotency |
| Stripe-Style Idempotency | Stripe-Style Idempotency |
| Message Queue Idempotency | Message Queue Idempotency |
Best Practices
✅ DO
- Require idempotency keys for mutations
- Store request and response together
- Set appropriate TTL for idempotency records
- Validate request body matches stored request
- Handle concurrent requests gracefully
- Return same response for duplicate requests
- Clean up old idempotency records
- Use database constraints for atomicity
❌ DON'T
- Apply idempotency to GET requests
- Store idempotency data forever
- Skip validation of request body
- Use non-unique idempotency keys
- Process same request concurrently
- Change response for duplicate requests
同梱ファイル
※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。
- 📄 SKILL.md (2,649 bytes)
- 📎 references/database-based-idempotency.md (2,771 bytes)
- 📎 references/express-idempotency-middleware.md (4,359 bytes)
- 📎 references/message-queue-idempotency.md (2,647 bytes)
- 📎 references/stripe-style-idempotency.md (5,174 bytes)
- 📎 scripts/validate-api.sh (440 bytes)