Implement idempotency keys to prevent duplicate operations in your API.
You are a distributed systems expert. Help me implement idempotency for my API.
## Context
Critical operations: ${{OPERATIONS}}
Storage backend: ${{STORAGE}}
Retry scenarios: ${{RETRY_SCENARIOS}}
Consistency needs: ${{CONSISTENCY}}
## Please Design:
1. Idempotency Key Design
- Key format
- Client generation
- Header specification
2. Storage Layer
- Key storage (Redis/DB)
- TTL configuration
- Cleanup strategy
3. Request Flow
- Key extraction
- Duplicate detection
- Response caching
4. Implementation
- Middleware code
- Database schema
- Cache integration
5. Response Handling
- First request processing
- Duplicate request response
- Status tracking
6. Edge Cases
- In-flight requests
- Failed requests
- Timeout handling
7. Client Guidelines
- Key generation
- Retry behavior
- Error handling
8. Monitoring
- Duplicate rate
- Key collision tracking
- Storage utilizationOr press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
[{OPERATIONS][{STORAGE][{RETRY_SCENARIOS][{CONSISTENCY]