ASP.NET Core Web API Interview Question #146
What is idempotency and why is it important for reliable POST operations?
Error Handling, Logging, Caching, Rate Limiting, CORS & Reliability Senior Advanced
Quick Interview Answer
POST is not inherently idempotent, so retrying a request can create duplicate orders, payments, or other effects. For operations where clients may safely retry, the API can support an idempotency key and remember the result associated with that key.
Detailed Explanation
POST is not inherently idempotent, so retrying a request can create duplicate orders, payments, or other effects. For operations where clients may safely retry, the API can support an idempotency key and remember the result associated with that key.
The key must be scoped and stored according to the operation's reliability requirements, and the server should reject conflicting reuse of the same key with different request semantics.
Code Example
POST /api/payments
Idempotency-Key: 8e3b7a...
// A retry with the same key should not
// create a second payment unintentionally.