In this guide ⌄
Disabling a button improves the interface. A guarantee about the operation, however, requires a check in the system managing the data.
What idempotency means
According to RFC 9110, section 9.2.2 , a method is idempotent when repeated identical requests have the same intended effect as a single request. The specification includes PUT, DELETE and safe methods. It does not require identical response codes or identical logs on every attempt.
POST does not automatically provide this property. An application can nevertheless define a deduplication protocol: recognise the same intention, retain its outcome and return it when a matching retry arrives.
If the client has not received a response, it does not yet know whether the server performed the operation.
The lost-response problem
Imagine creating a booking. The server records it, but the connection drops before the phone receives confirmation. The phone repeats the request and the server creates another booking.
No distracted user is required: each component may have behaved reasonably. What is needed is a stable operation identifier, reused by attempts representing the same intention.
| Case | Proposed behaviour | Required check |
|---|---|---|
| Same key, same data | Return the recorded outcome | Compare the content |
| Same key, different data | Report a conflict | Request fingerprint |
| New key | Evaluate a new operation | Permissions and validation |
This is an application contract proposed for the example. A real service must also document the key's scope, retention period and treatment of operations still in progress.
Why the check must reach the database
Two processes may simultaneously ask whether a key exists. If both read “absent” before either writes, a check performed only in application code can let both proceed.
A unique constraint with the correct scope, such as the account-and-key pair, lets the database reject the duplicate. The PostgreSQL constraints documentation explains these rules and their role in data integrity. Even in a SQLite lab, the constraint must be enforced rather than merely described in a comment.
Recording the key, performing the local effect and recording the result must be coordinated. If a key is recorded before the operation without managing states, an interruption can leave a request marked as seen but never completed.
A local lab with two attempts
DEMONSTRATION LAB
Demonstration booking without external services
The lab creates SQLite tables for requests and bookings. A transaction records account, key, content fingerprint and result together with the booking.
When the same key is repeated with the same data, the test checks that the returned identifier matches and that only one booking exists. Reusing the key with different content must produce a conflict.
The lab tests local behaviour and includes two concurrent connections. It does not simulate payments, email delivery or distributed transactions.
A call to an external service introduces another boundary. The local database may commit while the remote outcome remains uncertain, or the reverse may happen. That case requires a protocol with the provider and a reconciliation strategy; a local transaction cannot make an operation spanning two systems atomic.
Designing for retries
-
Define what identifies a single user intention.
-
Associate the key with the authenticated account and operation type.
-
Compare the data too: a key must not silently authorise different content.
-
Prevent concurrent races with rules enforced by the database.
-
Retain and return the outcome defined by the application contract.
-
Test interruptions, concurrency, key expiry and external systems.
Do not use a session token as a universal operation key: a session contains many different intentions. Key retention also needs a design. Once its record has been deleted, a late retry may no longer be recognised.
A pre-release checklist
CHECKLIST
Check your project
This is a useful topic to address in a Row Tech project before the first duplicate occurs: a confirmation screen describes an outcome the backend needs to be able to demonstrate.
Download the lab
Download the demonstration lab (ZIP) . The test uses local SQLite, two concurrent connections and content checking. It performs no payments or sends.