The problem
A channel sends a transfer. The integration layer forwards it. The backend takes too long, and the caller gives up after its timeout. Nobody on the calling side knows whether the money moved. Swap the transfer for an order, a booking or a policy change and the problem is the same: nobody knows whether the write landed.
Most duplicate postings start here. The caller treats the timeout as a failure and sends the request again. The first request had in fact succeeded, a little late. The customer is debited twice.
A timeout is not a failure. It is a third outcome: unknown. The tactics below make that outcome explicit and give every team the same way to resolve it.
Tactic 1: One timeout budget, shrinking at every hop
Timeouts set independently by each team are the root cause. If the gateway waits 10 seconds and the integration layer waits 30, the gateway gives up while the work is still running behind it.
Set one end-to-end budget at the edge, then make each inner hop strictly shorter than the hop that calls it. The innermost system must always answer, or be abandoned, before its caller stops listening.
| Hop | Timeout | Why |
|---|---|---|
| Channel → gateway | 10.0 s | The user-facing budget. Everything else fits inside it. |
| Gateway → integration | 9.0 s | Leaves the gateway time to return a clean response. |
| Integration → backend | 7.5 s | Leaves time for one status inquiry after a timeout. |
| Status inquiry | 1.0 s | Short and read-only. Runs only when the write timed out. |
The numbers are illustrative. The rule is the point: inner timeouts are shorter than outer ones, and the difference is large enough to do something useful.
Tactic 2: The originator creates the idempotency key
A retry is only safe if the receiver can recognise it. That needs a key that is created once, by the system where the business action started, and carried unchanged through every hop.
- Create it at the origin. The channel generates the key when the user confirms. A key generated by a middle layer changes on every retry and protects nothing.
- Never regenerate it. Gateways and integration flows forward the key. They do not replace it.
- Store it with the result. The system that performs the write saves the key and the outcome in the same transaction as the write itself.
- Return the stored result on a repeat. The same key with the same payload gets the original answer. The same key with a different payload is rejected.
Tactic 3: Put three outcomes in the contract
Most API contracts offer two answers: success and error. Callers then have to guess what a timeout means. Give them a third answer they can program against.
HTTP/1.1 202 Accepted
Content-Type: application/json
Location: /transfers/status/7f3c2a9e-51d4-4c0b-9a6e-2f1b8c4d7e10
Retry-After: 5
{
"status": "PENDING",
"idempotencyKey": "7f3c2a9e-51d4-4c0b-9a6e-2f1b8c4d7e10",
"statusUrl": "/transfers/status/7f3c2a9e-51d4-4c0b-9a6e-2f1b8c4d7e10",
"retryAfterSeconds": 5
}
| Outcome | Meaning | What the caller does |
|---|---|---|
| Completed | The write happened. | Show success. |
| Rejected | The write did not happen and will not. | Show the reason. A new attempt needs a new key. |
| Pending | The write may or may not have happened. | Tell the user it is being processed. Ask the status endpoint. Do not send a new request. |
Tactic 4: Resolve unknowns by asking, not by repeating
When the write to the backend times out, the integration layer should not retry the write straight away. It should ask.
-
Ask the backend for the status of that key
One short, read-only inquiry. If the backend says completed or rejected, return that answer and stop.
-
If the backend has never seen the key, retry the write once
The first request did not arrive. A retry with the same key is safe.
-
If the inquiry also fails, return pending
Record the item in a pending table with the key, the time and the payload hash. Do not guess.
-
Let a background job close every pending item
The job repeats the inquiry with increasing gaps until it gets a final answer. Anything still open after an agreed time goes to a person, with the evidence attached.
Do not send an automatic reversal for a pending item. If the original did not happen, the reversal credits money that was never debited. Reverse only after the status inquiry confirms the original completed.
Tactic 5: Write down what may be retried
Retry behaviour should be a published rule, not a library default.
| Situation | Retry? | Rule |
|---|---|---|
| Read request, any failure | Yes | Up to two retries, with backoff and jitter, inside the budget. |
| Write, connection refused | Yes | The request never left. Same key. |
| Write, timeout after sending | Not directly | Inquire first. Retry only if the key is unknown to the backend. |
| Write, business rejection | No | The answer is final. Retrying repeats the rejection. |
| Write, backend overloaded | Later | Respect the wait the backend asks for. Do not add load to an overloaded system. |
Retry at one layer only. If the channel, the gateway and the integration layer each retry three times, one user action becomes 27 backend calls at the exact moment the backend is struggling.
Tactic 6: Reconcile every day
Even with all of the above, something will slip through. A daily comparison of what the channel believes against what the backend recorded catches it before the customer does.
- Match on the idempotency key, not on amount and time.
- Report three lists: completed on both sides, completed on one side only, and still pending.
- Treat the “one side only” list as a defect list. Each entry points to a path where the rules above are not followed.
Pitfalls
- Showing “failed” on a timeout. The user tries again with a new key, and the protection is bypassed by design.
- Keys that expire too early. If stored keys are removed after an hour and a retry arrives after two, it is processed as new. Keep keys longer than the longest possible retry.
- Storing the key after the write. A crash between the two leaves a write with no record. Both belong in one transaction.
- A status inquiry that touches the slow path. If the inquiry depends on the same overloaded resource, it times out too. Make it a cheap lookup.
Checklist
-
Draw the hops and write each timeout next to it
Fix any hop where the inner timeout is not shorter than the outer one.
-
Confirm where the idempotency key is created
It must be the originating system, and no hop may replace it.
-
Add the pending outcome and a status endpoint to the contract
Agree the wording the channel shows to the user for a pending result.
-
Replace blind retries with inquire-then-retry
Remove retries from every layer except one.
-
Run the daily reconciliation and review the exceptions weekly
The exception count is the measure of whether the design works.