Idempotency
Idempotence keeps the business effect of the same logical operation stable upon repetition. A unique identifier connects all attempts with the stored result.
- KeysCombine all attempts of an intention.
- Saved resultRepetition gives the same result.
- Same intentionOther content is a conflict.
Context
Why this is important
Repeats are normal for lost answers. Without Idempotence, the same call can act twice, here a double load. Deciding if and when to repeat is a matter for Retry.
This building block explains safe repetition of the same operation. For the decision on re-testing, see Retry.
At a glance · Repeat with the same key
A burden despite repetition
The payment module sends B-1042 with the key pay-B-1042 to the external provider. The first answer is lost.
This is how you read the picture
- Keys With "pay-B"1042“ the provider recognizes the repetition as the same order.”
- Saved result The result memory reports "Z-"9 Already present, the burden remains 1 × 49,90 €.
- Same intention Both experiments carry the same key and the same 49,90 €Only then will it be considered a duplicate.
- runningPayment moduleAnswer arrived, no retry
- runningPayment providerLoaded once
- NoteResult storeis not needed
- runningLoading of B-10421 × 49,90 €
1Loads of B-1042
Benefits & limitations
Helps if:
- A stable key associates retries with the same operation and resolves an uncertain outcome.
- Atomically linking the key, request and change protects the business effect against concurrent or repeated execution.
- External effects need their own duplicate detection and status resolution beyond the local database transaction.
Boundaries
- The key must identify the same intent consistently across all attempts; a new key for each attempt defeats the protection.
- The stored result needs a retention period and storage space; once it expires, a retry is treated as a new request.
- Idempotency makes retries safe; Retry decides whether to try again.
In practice
- Define a stable identifier for each logical operation and bind it to the unchanged request content. Reusing the key with different content needs an unambiguous conflict response.
- Store the key, business change and result to return within the same atomic boundary. A retry then returns the known result rather than triggering a second effect.
- Handle external effects using their own duplicate detection or status query. Retry controls attempts; Transactional Outbox safeguards message delivery.
Read the detailed explanation
An operation is idempotent if executing it repeatedly with the same business intent leaves the same state as executing it once. The response data may differ; what matters is the effect on state. Setting a target state can therefore also be idempotent.
A stable key identifies retries as the same logical operation. The key, request fingerprint, business change and retrievable result must be linked atomically; reusing a key with different request content receives a defined conflict response. Uniqueness constraints and a transaction ensure a single change when retries arrive concurrently. External effects fall outside this local atomicity and need their own delivery and recipient strategy.
Retry decides when to try again; idempotency ensures that the same key with the same request identifies the same operation. Transactional Outbox handles subsequent external delivery.
With HTTP, the Idempotency-Key header often carries the key, such as pay-B-1042 in the shop.
Check your understanding
Test yourself in three stages
ReadingCheck in the picture
How often is B-1042 If the answer is lost and the key is missing?
View the solution with justification
Twice, each 49,90 €. With key pay-B-1042 Only once, as Z-9.
ApplyingTransferred to a new situation
The answer to the first attempt was lost. What does the payment send on the second attempt?
View the solution with justification
The same key pay-B-1042 with the same 49,90 €, so that the provider recognizes the existing result.
EvaluateWeighing an alternative
Should the payment generate a new key for each attempt? How do you weigh up?
View the solution with justification
New keys act independently, but the provider cannot recognize the repetition as the same intention and could charge again. The fixed key protects against double effect.
Explore further
These building blocks continue the thoughts of this page.
References
- IETF · HTTP Semantics (RFC) 9110) (opens in new tab)Normalizes HTTP methods, secure and idempotent operations, and status codes.
- AWS Builders’ Library · Idempotent APIs (opens in new tab)Explains power keys and secure repetitions of distributed calls.
- Stripe · Idempotent Requests (opens in new tab)Concrete API contract on power keys and repeated requests.