J/CONNECTED SYSTEMS

API idempotency for duplicate requests and safe retries

Design API idempotency around logical operation identity, concurrent duplicates and safe retries after a lost response.

Start a conversation
JASMIR / A FIELD OF POSSIBILITY
01 / Connected systems

Why can a request succeed after the sender times out?

A sender can lose a response after the receiver has already performed the action. Retrying may be necessary, but the receiving system cannot infer from the connection alone whether the request is new. Duplicate delivery is therefore a normal design condition, not an exotic edge case. The important question is whether repeating the request changes the business outcome in an unintended way.

02 / Connected systems

How should an API recognize the same logical operation?

Identify the logical operation independently of each transport attempt. Agree where its identifier comes from, the scope in which it is unique and how long the receiver needs to recognize it. Record the outcome at a boundary that prevents two simultaneous attempts from creating two effects. Define the response when the same identifier arrives with different content. Include external actions such as notifications or downstream messages in the reasoning, not only a database row.

03 / Connected systems

How long should the receiver remember an idempotency key?

Remembering every request forever creates storage and information-handling obligations. A short recognition window may allow late duplicates. Choose a policy using the business lifecycle and delivery conditions, then document its limits. Some operations naturally replace state and are easier to repeat; others create irreversible effects. Do not label an entire API idempotent without examining the actual operations and their side effects.

04 / Connected systems

What should duplicate-request tests cover?

Prepare operation identity rules, duplicate scenarios, outcome storage behavior and replay instructions. Test a lost response, concurrent duplicate and mismatched payload. Operators should know whether replay is safe and how to find the first result without inspecting unrestricted payload logs.

05 / Connected systems

How do downstream effects change safe replay?

Review duplicate behavior at the point where business effects occur. A request cache may recognize repetition while a separately sent notification still happens twice. Trace the complete operation and document any side effect whose behavior differs from the stated duplicate-handling rule, rather than hiding that difference behind one label.

A retry that creates one production request

This illustrative contract submits an approved order to a production-request service. The caller chooses an operation key once and keeps it for every retry of that submission. The key below is an example identifier, not a credential or a universal API requirement.

First attempt — submit the approved order
POST /production-requests HTTP/1.1
Content-Type: application/json
Idempotency-Key: release-order-1042-v7

{"orderId":"1042","approvedVersion":7}
Committed result — the caller loses this response
HTTP/1.1 201 Created
Location: /production-requests/R-17
Content-Type: application/json

{"requestId":"R-17","status":"queued"}

The service has created R-17, but the caller sees a timeout. Under this contract, repeating the same key and body returns the recorded status and body for R-17. It does not create R-18. “Queued” means the submission exists; it does not say production has started.

Where the guarantee must hold

Authenticate and authorize every attempt before returning a stored result. Scope the key to the authenticated tenant and operation; never use a caller-supplied tenant value as authority. Store a fingerprint of the validated business inputs alongside the result. A durable uniqueness constraint must arbitrate concurrent attempts, rather than two processes independently checking an in-memory map.

Where all three records share a transactional database, commit the production request, replay result and outgoing event together. A worker can deliver that event afterward. The receiving system still needs duplicate handling: an outbox does not make an external action happen exactly once. AWS’s transactional outbox guidance explains this failure boundary.

Acceptance checks for this contract
ScenarioExpected behavior
Response lost after commitRetry returns R-17; one production request exists.
Two attempts arrive togetherOne attempt claims the operation. The other receives the documented pending or completed result.
Same key, changed approvedVersionReject the mismatch; do not replay an unrelated result or create a second request.
Another tenant uses the same keyApply its own authorization and namespace. Never disclose R-17 across tenants.
Database commits; event delivery failsThe outgoing event remains available for retry. The consumer handles repeated delivery.
Recognition window expiresReconcile the business operation before retrying an uncertain submission; a new key is not proof that the old operation failed.

Why this matters to the project manager

A connection failure should create a visible pending decision, not two jobs for someone to untangle. Keeping the order, submission and retry identity connected gives the PM a result to inspect and a safe recovery path. The business rule is the deliverable; the HTTP header is only one part of it.

Bring one difficult handoff to Jasmir’s systems integration team. We can map the ownership, failure paths and first useful release around your workflow. See how these decisions fit together in the illustrative CRM and ERP project.

Questions worth checking.

  • Does identity describe the business operation rather than the network attempt?
  • Are concurrent duplicates handled?
  • What happens when an identifier is reused with different content?
Start a conversation

NEXTYOUR VISION. OUR CODE.

What’s your
next big thing?

↗

A new idea. A difficult workflow. A better way forward.
Let’s find the right place to begin.

contact@jasmir.io ↗