CloverlightCloverlight
← Back to blog
Published · By Berke Gözübüyük

Idempotent purchasing: how to make sure an order is never bought twice

Short answer: make the purchase step idempotent. Before pressing Place order, check a persistent journal for this order; if it is already marked placed or reconciled, stop. Write the journal entry at the moment of commitment, lock each buyer profile so only one job can use it, and read the resulting Amazon order ID back from order history instead of assuming the click worked.

How double purchases actually happen

  • The browser crashes after Place order but before the result is saved. On restart, the order still looks unbought.
  • A network timeout on the confirmation page is treated as failure and the job is retried.
  • Two queues pick the same order because the “claimed” state lived only in memory.
  • A person buys an order manually while automation is also processing it.

The rules that prevent it

  1. Global uniqueness. A marketplace order ID can exist once in the pool — duplicates are rejected at ingest.
  2. Explicit states. An order moves through named states (claimed → committing → placed → written back). “Committing” is recorded before the click, so a crash leaves evidence.
  3. A persistent journal. Placed and reconciled orders are never bought again — not after a restart, not from a second queue.
  4. One job per buyer profile. A profile lock prevents two carts in the same account.
  5. Read back, don't assume. The Amazon order ID and total are matched in order history by item and amount.

What to do with an order stuck in “committing”

Never retry it automatically. An order interrupted during commitment needs a human look at the buyer account's order history: if the purchase exists, record it; if not, release it. This single rule removes almost every double-purchase scenario.

Cloverlight Order Bot implements these states and the journal end to end, and routes any ambiguous order to manual review instead of guessing.

Frequently asked questions

What does idempotent mean for purchasing?

Running the purchase step more than once for the same order has the same effect as running it once — the item is bought a single time no matter how many retries happen.

Should a timed-out purchase be retried automatically?

No. A timeout after the order button may have succeeded. Check the buyer account's order history first, then record or release the order.

Have a question about your own operation?

Tell us what you're working on and we'll get back to you by email.

Contact us