SMM API Timeouts: Reduce Duplicate Order Submissions

When an order-creation request times out, keep its outcome unresolved until you have evidence of what happened. The request may have reached the server even if your application did not receive a usable response. Sending it again can create another order, so a timeout should not automatically return the purchase to the submission queue.

Build the workflow around a durable local order intent. Allow one worker to claim that intent, save a returned order ID promptly, and send ambiguous outcomes to a reconciliation queue. This reduces avoidable repeat submissions while preserving a route for resolving uncertainty. It does not create server-side duplicate protection where none is documented.

The original downloads include a state diagram, a five-event incident log, four failure scenarios and a runnable SQLite exercise. The records and IDs are DEMO. The exercise uses local files and simulated responses only; it cannot contact AlwaysCompleted or spend funds. The public documentation was checked on 26 November 2026.

Create one durable intent for one approved purchase

An intent is your application's record of the purchase the customer approved. Give it a local reference before a worker sends the request. Save the selected service, destination, required inputs, approved quantity or other relevant unit, offer version and creation time. Keep the API key out of that record and out of diagnostic logs.

The intent must have a clear meaning. A second click on the same confirmation should refer to the existing intent. A genuinely separate purchase needs a different intent and its own approval. Do not use the same local reference for different service selections merely because they share a destination.

Store a stable representation or hash of the approved inputs. If an existing intent arrives with different inputs, stop and ask the application to resolve the mismatch. Quietly replacing the first payload would make it impossible to tell what the original worker tried to submit.

The local reference does not become an API order ID. The AlwaysCompleted API reference documents a returned order identifier for successful creation and uses order IDs in status requests. Retain the local intent and the returned identifier as separate fields. A local reference is not evidence that an order exists remotely.

Claim the work before making the external request

Use a durable state transition that only one worker can win. In the downloadable example, a conditional database update changes Draft to Sending. A second worker cannot make that transition after the first has claimed the same intent.

Disabling a button improves the interface, but it cannot cover another browser tab, a queued duplicate or a worker restart. The durable claim belongs in the backend that controls submission. Keep the claim and its timestamp available to the recovery process.

Do not hold a long database transaction open while waiting for the network. Commit the claim, perform the external operation and then persist the result. That structure leaves an unavoidable interval in which the external result and the local record may differ. The recovery policy must recognise that interval instead of assuming that a restart means nothing happened.

The demonstration shows a local SQLite transaction boundary, not a production deployment design. A real distributed worker system needs equivalent atomic ownership, durable storage, recovery rules and monitoring suitable for its architecture. A lease expiry by itself must not make an uncertain creation safe to repeat. The example does not implement worker identity or fencing, timestamps for detecting abandoned work, or production recovery scheduling. Its recovery function changes every Sending record only because the demonstration has no live workers; a real system must identify abandoned work without taking over an active attempt.

Keep client workflow states distinct from order statuses

Use names that describe what your application knows about submission. They are not AlwaysCompleted delivery statuses.

Local state Meaning Permitted next action
Draft Approved input exists and this intent has not been claimed for submission Validate and let one worker claim it
Sending One worker has claimed the intent; external outcome may still be unresolved Wait for that attempt or investigate recovery
Confirmed A usable external order ID has been saved Read that order's status using its ID
Unknown outcome Transmission or persistence left the creation result uncertain Reconcile evidence; block automatic creation retry
Rejected A local validation failure or positively established rejection prevents this attempt Correct the cause and obtain the appropriate new decision

A response that cannot be parsed is not a positive rejection. Nor is an arbitrary HTTP failure proof that no side effect occurred. Define the rejection evidence your actual client can recognise; leave anything else unresolved.

MDN's POST method reference explains that repeated identical POST requests can have additional effects, including creating duplicate orders. Your retry policy must therefore depend on the operation and its known outcome, not just on whether the transport library reported an error.

Persist the returned order ID before continuing the workflow

When a validated success response includes an order ID, save it with the intent immediately and make that persistence part of the transition to Confirmed. Downstream status polling, customer updates and support records should use the saved mapping.

The difficult case is a process crash after the response arrives but before the ID is committed. The server may have created the order while the local database still says Sending. A restarted worker cannot reconstruct the missing identifier from wishful thinking, and a second creation request would add uncertainty.

The safe recovery action in this exercise is conservative: an abandoned Sending record becomes Unknown outcome. That also covers a crash after the claim but before transmission. In that second case the server may have received nothing, but the persisted evidence alone does not establish which side of the call the crash occurred on.

A separately durable response journal can improve recovery if your system is designed to capture it safely. It does not eliminate every failure window. Avoid promising exactly-once remote creation based solely on a local lock or transaction.

Reconcile the unknown outcome using actual evidence

The AlwaysCompleted developer guide explicitly advises pausing automatic resubmission when creation was sent but no usable response or ID arrived. It points to available dashboard records and technical support for unresolved cases. It does not establish an idempotency key or a search endpoint for your local reference.

Give the reviewer a concise evidence bundle: local intent reference, attempt time and timezone, selected service, destination, relevant quantity or inputs, current local state and any safely retained response information. Exclude the API key. Preserve the customer's approved request so the reviewer can distinguish this attempt from another similar order.

A plausible dashboard match is a lead to investigate, not an automatic identity proof. Two purchases can share a target and quantity. Record why the identified order belongs to this intent, then save the confirmed external ID with the reconciliation evidence.

A balance difference alone is also insufficient to identify a particular order. Other activity or timing can affect the observation. Use evidence that establishes the specific outcome rather than treating an approximate debit as a substitute for an order mapping.

If the investigation positively establishes that no order was created, record that finding and the authority for a fresh submission. A new authorised attempt should remain traceable to the unresolved history. If the evidence remains inconclusive, retain the hold and communicate the next review point. The existing campaign-delay message guide helps explain an unresolved situation without inventing a delivery promise.

Work through the five-event incident

In the DEMO workbook, one customer approval produces intent DEMO-I-001. A worker claims it, the simulated service returns order 92001, and the worker crashes before saving that response. The recovery process finds the abandoned claim and moves it to Unknown outcome. A later reviewer records evidence linking the simulated order to the intent and confirms that mapping.

The important detail is what the local database knew at each event. After the crash, it did not contain 92001; only the teaching scenario tells us the simulated remote outcome. The automated recovery must act on the stored uncertainty. It cannot use the author's knowledge to pretend that the missing ID was available to the real application.

The workbook also covers duplicate clicks, a timeout without a usable response, a malformed response and a worker that dies before the external call. For each, the expected behaviour describes whether another submission is blocked and what evidence is needed next.

Run the failure exercise locally

With Python 3 available, save the Python download and run:

python3 ac288-intent-ledger.py

It creates a temporary SQLite database, uses synthetic inputs and checks six boundaries: duplicate claims, altered payload under the same intent, timeout recovery, crash after a response but before persistence, a malformed success response and explicit local rejection. The authoring run passed all six. The temporary database is removed at the end, and the program contains no networking code.

The crash exercise deliberately leaves a record in Sending, reopens the database through another connection and applies recovery. It then verifies that automatic claiming remains blocked until a supplied reconciliation record confirms the outcome. These are tests of the teaching state transitions, not proof that an existing live integration has the same protections.

Before enabling real creation, adapt the design to your own storage and worker model, test the relevant failure boundaries and make the recovery queue usable by an authorised person. Start connection checks through the documented read-only route in the developer guide. A new paid order is not a harmless connectivity probe.

By AlwaysCompleted · Published