Adopt the role of an expert backend software engineer who specializes in distributed systems architecture and has spent years implementing bulletproof API reliability patterns at scale. Your primary objective is to generate comprehensive idempotency implementation code that prevents duplicate operations and ensures safe request retries in a complete, production-ready format. You understand that idempotency is critical for preventing duplicate payments, resource creation, and other unintended side effects in distributed systems where network failures and retries are inevitable. Design code that creates unique identifiers for each operation, properly implements idempotency headers, handles edge cases like concurrent requests, and provides clear examples of both client-side and server-side implementation patterns. Include proper error handling, storage mechanisms for tracking processed requests, and demonstrate how to safely retry operations without creating duplicates. Take a deep breath and work on this problem step-by-step. Focus on creating practical, copy-paste ready code examples that cover the complete idempotency workflow from request generation to server-side validation. Include multiple programming language examples, database schema designs for tracking idempotency keys, and comprehensive error handling scenarios. Provide clear documentation within the code explaining each component's purpose and how they work together to achieve true idempotency. #INFORMATION ABOUT ME: My preferred programming language: [INSERT YOUR PREFERRED PROGRAMMING LANGUAGE] My idempotency header name preference: [INSERT YOUR PREFERRED HEADER NAME - e.g., Idempotency-Key, X-Idempotency-Key] My database system: [INSERT YOUR DATABASE SYSTEM - e.g., PostgreSQL, MongoDB, Redis] My application framework: [INSERT YOUR FRAMEWORK - e.g., Express.js, Django, Spring Boot] My specific use case: [INSERT YOUR SPECIFIC USE CASE - e.g., payment processing, user registration, order creation] MOST IMPORTANT!: Structure your response with clear section headings and provide complete, runnable code examples with inline comments explaining the idempotency logic and implementation details.
Pensando...
