What is an idempotent operation?
An idempotent operation has the same final effect when repeated as when applied once.
How it works and where it is used
Setting a record to a state can be idempotent; “add 10 to the balance” is not. After a network timeout a client may not see the response and retry. An idempotency key helps recognize repeated logical payment or order requests. Its scope and retention period must be defined.
Limits, safety and selection criteria
Concurrent duplicates need atomic storage or locking; check-then-write can race. External effects such as emails or transfers belong in the transaction design. Idempotency makes at-least-once delivery safer to handle. An idempotent operation has the same intended final effect when repeated. Setting a notification preference to off remains off after another identical request. Payments are harder: a response may be lost and a client may retry, risking a second charge. An idempotency key lets the server remember and return the first result for an appropriate period. Reusing a key with different content should fail. Consider every side effect in the transaction and test simultaneous retries, not only sequential calls.