Contact us
Insights

Idempotency for ERP order imports

How to make an order import safe to resend, so a retry or a rerun never puts the same order into your ERP twice.

The problem

Why the same order arrives twice

Integrations retry. A web shop resends a webhook when it doesn’t get a reply in time, a scheduled job is rerun after a failure, or someone presses import again because the screen froze. In each case the ERP may already have the order. If the import simply creates a new sales order every time it is asked, you end up with two orders, two picks, and sometimes two invoices for one customer purchase. Idempotency is the property that fixes this: sending the same order once or five times leaves the ERP in the same state.

Start with a reference that never changes

Every order needs a key that identifies it across systems and never changes: usually the web shop’s order number, stored in a dedicated field on the ERP sales order. Avoid anything that can change after the order is placed, such as the customer’s name, the order total, or the date it was imported. If one platform feeds several ERPs or one ERP takes orders from several shops, prefix the key with the source, for example SHOP-100245, so two channels can never collide.

The pattern

Four rules for a safe order import

Look up before you create

Check the ERP for the order’s key first. If it exists, update or skip it; only create a new order when the key is new.

Let the ERP enforce uniqueness

Where the ERP allows it, make the key field unique, so two imports running at the same moment can’t both succeed.

Record what was done

Log each message with its key and outcome: created, updated, skipped, or rejected. That log answers “did this order arrive?” in seconds.

Treat changes as updates

A later message for the same order, such as a cancelled line, should change the existing order, not create a second one.

Batches and partial failures

File and batch imports need the same care. For example: a nightly file of 400 orders stops at order 260 because one has an unknown product code. If the job is rerun from the top, the first 259 orders must be recognised and skipped, the problem order fixed, and the remaining orders imported. Processing each order on its own, with its own outcome in the log, makes a rerun safe and turns one bad record into a single line to fix rather than a failed night.

Payments, refunds, and stock need keys too

Orders are the obvious case, but anything that changes a balance needs the same protection. A payment should carry the payment provider’s transaction ID, a refund its refund ID, and a stock adjustment the ID of the movement that caused it. Without those keys a retried payment can clear an invoice twice, and a resent stock movement can leave the ERP thinking you hold more or less than you do.

Testing

How to check an import is idempotent

Step 1 of 4

  1. Import an order, then send exactly the same message again. The ERP should still hold one order, and the log should show the second one skipped.

  2. Run two imports of the same order in parallel. Only one should create it.

  3. Cancel a line on the web and resend. The existing ERP order should change, with no new order created.

  4. Stop a batch part way through, then rerun it. Orders already imported should be skipped and the rest created.

Duplicate orders in your ERP?

Tell us where orders come from and what happens when an import is retried. A few lines are enough.

Tell us what’s not working