backend-idempotency
Use when the user asks about idempotency keys, a payment endpoint that charges twice when the client retries, safe retries, duplicate requests or…
от j4flmao★ 47 звёзд на GitHub
Установить backend-idempotency в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Backend Idempotency
Purpose
Guarantee exactly-once execution for mutating operations using idempotency keys, enabling safe retries without duplicate side effects. Idempotency is the foundation of reliable distributed systems — without it, network retries cause duplicate orders, double charges, and inconsistent state.
Agent Protocol
Trigger
Exact user phrases: "idempotency", "idempotent", "idempotency key", "exactly-once", "retry safety", "deduplication", "duplicate detection", "idempotent endpoint", "safe retry".
Input Context
- Which endpoints need idempotency guarantees.
- Existing data store (Redis, PostgreSQL, DynamoDB).
- Current retry configuration.
Output Artifact
Idempotency key handling design. No file unless requested.
Response Format
Endpoint: {method} {path}
Key Source: {client-provided|server-generated}
Storage: {store type}
TTL: {duration}
Completion Criteria
- Idempotency key storage implemented with TTL.
- Key uniqueness enforced at database level.
- Response caching: same key returns same response.
- Expired keys handled gracefully.
- Concurrent requests with same key resolved (first wins or lock).
Max Response Length
4 lines per endpoint. 15 lines for full solution.
Architecture Decision Tree
Which Idempotency Strategy?
Is the operation naturally idempotent? (PUT, DELETE, same result every time)
├── Yes → No key needed, just use the resource identifier
└── No → Is the operation a creation (POST, different result each time)?
├── Yes → Client-provided idempotency key required
│ ├── Does the client always retry on network errors?
│ │ ├── Yes → Always require key on mutating endpoints
│ │ └── No → Still require it — clients are unreliable
│ └── Is the key collision possible?
│ ├── Yes → Use UUID v4 or v7 for key generation
│ └── No → Use business key (invoice ID, order number)
└── No → Server-generated idempotency based on request hash
├── Same request body within TTL → deduplicate
└── Different body → new operation
Key Source Decision
Who controls the idempotency key?
├── Client-provided (Idempotency-Key header)
│ ├── PRO: Client controls retries, predictable semantics
│ ├── CON: Badly-behaved clients can exhaust keys
│ └── Use when: External API, third-party integrations
└── Server-generated (request hash or business key)
├── PRO: No client cooperation needed
├── CON: Same body always returns same result (may not be desired)
└── Use when: Internal services, idempotent by design
Storage Backend Decision
What are your latency and consistency requirements?
├── Redis → Fast (~1ms), TTL-based expiry, atomic operations
│ ├── PRO: Low latency, built-in TTL
│ ├── CON: Data loss on node fail (if not persisted)
│ └── Use when: High-throughput, short TTL (< 24h)
├── PostgreSQL → Durable, transactional, complex queries
│ ├── PRO: ACID compliant, survives crashes
│ ├── CON: Slower (~5-10ms), requires cleanup job
│ └── Use when: Financial operations, long TTL (> 24h)
└── DynamoDB → Serverless, auto-scaling, TTL built-in
├── PRO: No ops, pay-per-use
├── CON: Eventually consistent by default
└── Use when: AWS ecosystem, variable throughput
Workflow
Step 1: Client Sends Idempotency Key
Clients include Idempotency-Key header (UUID v4 or v7) on POST/PUT/PATCH requests. The key is a client-generated unique identifier for the operation.
Step 2: Server Checks Storage
async function handleRequest(req, res) {
const key = req.headers['idempotency-key'];
if (!key) return res.status(400).json({ error: 'Idempotency-Key header required' });
const existing = await idempotencyStore.get(key);
if (existing) {
// Return cached response — including error responses
return res.status(existing.status).json(existing.body);
}
// Process the request
const result = await processPayment(req.body);
await idempotencyStore.set(key, { status: 200, body: result }, { ttl: 3600 });
return res.json(result);
}
Step 3: Handle Concurrent Requests
When two requests with the same key arrive simultaneously, only one should succeed. Use database-level locking:
-- PostgreSQL: INSERT ... ON CONFLICT
INSERT INTO idempotency_keys (key, status, body, created_at)
VALUES ($1, 'pending', null, NOW())
ON CONFLICT (key) DO NOTHING
RETURNING *;
-- If no row returned, another request holds the key — return 409 Conflict
// Redis: SET NX with TTL
const acquired = await redis.set(`idempotency:${key}`, 'pending', {
NX: true,
EX: 3600, // TTL in seconds
});
if (!acquired) {
// Key exists — wait for completion or return 409
const existing = await redis.get(`idempotency:${key
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- references/exactly-once-strategies.md
- references/idempotency-distributed.md
- references/idempotency-failure-modes.md
- references/idempotency-keys.md
- references/idempotency-middleware.md
- references/idempotency-patterns.md
- references/idempotency-storage.md
- references/idempotency-testing.md
FAQ
Что делает скилл backend-idempotency?
Use when the user asks about idempotency keys, a payment endpoint that charges twice when the client retries, safe retries, duplicate requests or deduplication. Produces an idempotency-key store and middleware. Not for message consumer dedupe in brokers (use backend-message-queue) or locks (use backend-distributed-locking).
Как установить скилл backend-idempotency?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл backend-idempotency запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
AnthropicToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
access
AnthropicManage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
configure
AnthropicSet up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
access
AnthropicManage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…