The request timed out. Was the order created?
Stable retry keys, atomic records and the boundary of the promise
A timeout leaves the outcome unknown. Safe retries need stable operation keys, unique constraints and atomic effect records.
A client asks an API to create an order. The response never arrives. A timeout tells the client it did not receive an answer in time. It does not tell it whether the server saved the order.
This is a different question from whether an acknowledged write survives a crash.
Identify the logical operation
The client creates an idempotency key before its first attempt and reuses it for retries of that operation. A new order gets a new key; a retry does not.
The server stores the key and result so it can recognize the same operation. Scope keys by the relevant tenant, account and operation. Check that a reused key refers to compatible request parameters; do not silently accept the same key with a different amount.
A bounded retention period is part of the contract. An expired record cannot prevent duplicates forever.
A lookup followed by an insert is not enough
Two requests can both observe “key missing” and both perform the effect. A unique constraint is needed to arbitrate the race.
Likewise, creating an order and recording the key in separate transactions leaves a crash window. For a local database effect, save the business change and the idempotency record atomically:
This is a transaction outline, not executable SQL. A conflicting request must follow a defined in-progress/completed policy rather than blindly proceeding. Errors and rollback behavior also need explicit semantics.
The crash that a retry can survive
Suppose the order and key commit, then the server crashes before replying. A retry with the original key can find the saved result and avoid a second order.
A retry with a new key appears to be a new operation. The database cannot infer the client's abandoned intention from matching amounts alone.
The external-effect boundary
A PostgreSQL transaction does not include a remote payment provider or message broker. Calling either while a transaction is open does not make their effects atomic.
Use the downstream provider's idempotency contract when available. For durable publication intent, Transactional Outbox addresses a separate failure window. Consumers still need duplicate handling.
A small experiment
In a local test database, send two concurrent attempts with the same scoped key, then simulate losing the response after commit. Check that there is one business record and the retry returns the stored outcome. Repeat with different parameters under the same key and verify the request is rejected according to your contract.
Check yourself
The first request committed successfully and its response was lost. Does a retry with a newly generated key necessarily avoid a duplicate? No. Stable operation identity is what makes the retry recognizable. Idempotency requires client behavior, atomic storage and a defined lifetime together.