Core · Guide

Reliable ERP to PIM Integrations: Idempotency, Ordering, Retries and Replay
Why ERP to PIM integrations fail quietly
An ERP to PIM integration can look healthy for months while it duplicates relations, restores old weights and drops messages. The causes are mechanical. Message brokers deliver at least once. ERP event frameworks retry when an endpoint is slow. Parallel workers finish in a different order than they started. None of this shows up as an error, so the first signal is often a channel rejection or a customer complaint weeks later.
This article explains the four mechanisms that make the integration reliable: idempotency, per-SKU ordering, retries and the dead-letter queue with replay. It covers how each one works, which identifiers you need, and how to test the whole chain before go-live. The ERP-PIM integration architecture article shows where this sits in the full pipeline.
Why messages arrive twice, late or out of order
Duplicates and reordering are normal behavior of the components you integrate. The platform documentation says so plainly.
- ERP event frameworks retry. Microsoft documents that Dynamics 365 Finance & Operations retries failed business event deliveries, that consumers should use the control number in the payload to detect duplicates, and that delivery order is not guaranteed to match emission order.
- Event routers retry for a long time. AWS EventBridge, by default, retries delivery to a target for 24 hours and up to 185 times, with exponential backoff and jitter.
- The outbox pattern can publish twice. A message relay that crashes after publishing but before recording the publish will send the same message again. Consumers are expected to be idempotent.
- Queue order and processing order differ. Azure Service Bus documentation notes that sequence numbers guarantee the order in which messages are queued and retrieved. Processing order needs sessions. With two consumers, messages 1, 2 and 3 can complete as 2, 3, 1.
The conclusion for the PIM side is simple. The consumer has to protect itself against duplicates and reordering, because no layer upstream will do it completely.
Idempotency: apply each change exactly once
An idempotent receiver can safely receive the same message multiple times. For an ERP to PIM integration, that means a repeated or replayed message is acknowledged and discarded without changing data a second time.
Build the key from business identifiers
The idempotency key combines the ERP system key of the record with the ID of the event. The ERP system key is the stable identifier of the record: the material number plus client in SAP, the item id GUID in Business Central, the item number plus legal entity in Finance & Operations, the record type plus internal ID in NetSuite. The event ID comes from the event framework, such as the Finance & Operations control number or the id attribute of a CloudEvents message. The CloudEvents specification requires that source plus ID is unique for each distinct event and allows consumers to treat events with the same source and ID as duplicates.
Batch deltas need a key too. Use the ERP system key plus the batch run ID, so that re-running a failed batch does not apply the same rows twice.
Broker deduplication covers part of the problem
Some brokers offer duplicate detection. Azure Service Bus, for example, drops messages whose MessageId was already seen within a configurable window that defaults to 10 minutes and can be set as long as 7 days. That covers a sender retrying a send within the window. Replays next month, batch re-runs and two different events that carry the same change fall outside it. Keep your own store of applied keys in the integration or the PIM.
Write in one transaction
An idempotency check only helps if the write is atomic. If the consumer crashes after writing the attributes but before writing the variant relations, the retry finds the key absent, applies everything again and may duplicate the relations. Write the record, its relations and the applied key in one transaction. Where the PIM API cannot do that, make each part of the write idempotent on its own: set-based updates for relations and asset links.
| Write type | Idempotent form | Risky form |
|---|---|---|
| Attribute value | Set value to X | Increment or append to value |
| Variant membership | Set parent of SKU to model M | Add SKU to model M |
| Asset link | Set the hero image link to asset ID | Add image to gallery |
| Relation (accessory, successor) | Replace the relation set for type T | Append relation |
Ordering: never let an old event win
Ordering protects against regression. Without it, an older event that arrives after a newer one restores yesterday's weight, status or unit ratio, and nothing in the logs looks wrong.
Partition work by SKU
The first defense is to make sure only one worker handles a given SKU at a time. Use the SKU, or the ERP system key, as the partition key. In Apache Kafka, events with the same key are written to the same partition, and consumers read a partition in the order it was written. In Azure Service Bus, sessions give one receiver an exclusive lock on all messages with the same session ID, so they are processed in order. Different SKUs still run in parallel, which keeps throughput high.
Compare source timestamps with a watermark
Partitioning orders messages as they were queued. It cannot fix events that were queued in the wrong order, for example after a retry from the ERP side or a replay from the dead-letter queue. Store a watermark per SKU: the source change timestamp of the last change applied. When a message arrives, compare its source timestamp with the watermark. If it is older or equal, discard it and log it as stale. If it is newer, apply it and advance the watermark in the same transaction.
Use the timestamp of the change in the ERP. The moment a message reached the broker tells you nothing about when the change happened. Business Central exposes lastModifiedDateTime on items and in webhook notifications. SAP change documents and NetSuite's last modified date, where the record type exposes it, serve the same purpose.
Re-read current state where you can
A third technique reduces the damage of reordering further. When an event only says that a record changed, the consumer reads the current record from the ERP before writing. Two events for the same SKU then both lead to a read of the latest state. This costs API calls, so weigh it against the ERP's rate limits.
| Technique | Protects against | Limitation |
|---|---|---|
| Partition by SKU | Parallel workers overtaking each other on one SKU | Does not correct events queued out of order |
| Watermark per SKU | Stale events from retries, replays and late deliveries | Needs a reliable source change timestamp |
| Re-read current state | Applying outdated payload contents | Adds ERP API calls per event |
Retries: separate transient from permanent errors
Retries fix temporary problems and amplify permanent ones. The rule is to retry only errors that can succeed on a later attempt, and to send everything else to the dead-letter queue immediately.
| Error | Example | Action |
|---|---|---|
| Throttling | HTTP 429 from the ERP or PIM API | Wait for the Retry-After period, then retry with backoff |
| Temporary unavailability | HTTP 503, timeout, connection reset | Retry with exponential backoff and jitter, limited attempts |
| Lock or concurrency conflict | Record locked by another process | Retry after a short delay |
| Validation failure | Unknown unit code, missing mandatory field | Quarantine or dead-letter queue, no retry |
| Ownership violation | Payload targets a PIM-only field | Drop the field, log the violation, continue |
| Authorization failure | Expired credentials, missing permission | Dead-letter queue and alert, no retry |
Back off with jitter and retry in one place
Retry with exponentially increasing delays and add jitter, a random component, so that many failing messages do not retry at the same moment. The AWS Builders' Library also advises retrying at a single layer of the stack, because retries at several layers multiply the load on a system that is already struggling. When an API returns HTTP 429, RFC 6585 allows it to include a Retry-After header that says how long to wait. Honor it.
Log retries quietly and final failures loudly
Microsoft's retry pattern guidance recommends logging early failed attempts as informational and only the final failure as an error. That keeps alerting meaningful. Still log every retry with its cause, so recurring throttling or timeouts become visible in reports.
Dead-letter queue and replay
The dead-letter queue is the visible failure path. Every message that cannot be applied lands there with enough context for an administrator to understand and fix the problem without a developer.
What each dead-letter entry must contain
Store the full original payload, the idempotency key, the source change timestamp, the gate or step that failed, the error message, the number of attempts and the time of the last attempt. Brokers add some of this themselves. Azure Service Bus moves a message to its dead-letter queue when it exceeds the maximum delivery count, which defaults to 10, and records the reason. EventBridge adds the error code, error message and number of retry attempts to messages it sends to a dead-letter queue.
Dead-letter queues do not clean themselves
Azure Service Bus documents that there is no automatic cleanup of the dead-letter queue. Messages stay until someone processes them. Treat dead-letter depth and the age of the oldest message as operational metrics with an owner and an alert threshold.
Replay through the same gates
Replay sends a corrected or unchanged message back through the full pipeline: validation, whitelist, idempotency and ordering. That last gate matters. Microsoft notes that a message moved from the dead-letter queue back to a session-enabled queue loses its original order relative to other messages in the session. The watermark check catches the case where a newer change was applied while the old message sat in the queue. The replayed message is then discarded as stale, which is the correct outcome.
How to test reliability before go-live
Run these tests in a test environment with production-like data. Each one should pass before the integration carries live traffic.
- Send the same message twice. Confirm the second one is acknowledged, discarded and logged as a duplicate, and that no relation, variant or asset link is duplicated.
- Send an old event after a new one for the same SKU. Confirm the old event is discarded as stale and the newer value remains.
- Kill the consumer in the middle of a write. Restart it and confirm the record is either fully written or not written at all, and that the retry completes it once.
- Throttle the PIM or ERP API. Return HTTP 429 with a Retry-After header and confirm the integration waits and recovers without losing messages.
- Send an invalid message. Use an unknown unit code. Confirm it lands in the dead-letter queue or quarantine on the first attempt, with a readable reason.
- Fix and replay a batch of dead-lettered messages. Confirm each passes all gates again and that stale ones are discarded.
- Run reconciliation after the tests. Confirm ERP and PIM agree for every test SKU. The sibling article on reconciling ERP and PIM data describes how.
These mechanisms sit inside the enforcement pipeline described in ERP-PIM integration architecture. Size retries and replays against your ERP's published API limits, with headroom for live traffic.
Common mistakes
- Relying on broker deduplication alone. Broker duplicate detection works within a time window and only on the message ID (in Azure Service Bus with partitioning, the message ID plus partition key). Replays, batch re-runs and duplicate events with different IDs pass straight through.
- Using arrival time as the ordering criterion. The time a message reached the broker says nothing about when the change happened in the ERP. Compare source change timestamps.
- Retrying validation errors. A message with an unknown unit code will fail on every attempt. Retrying it wastes API capacity and delays the alert.
- Append-style writes for relations and assets. Append operations mean every duplicate creates another accessory link or gallery image. Use set-based writes.
- Leaving the dead-letter queue unowned. Failed messages accumulate silently. Name an owner, set thresholds on depth and age, and review the queue as part of daily operations.
Sources
- Idempotent Receiver, Enterprise Integration Patterns
- Business events overview, Dynamics 365 Finance and Operations
- Retrying event delivery, Amazon EventBridge
- Using dead-letter queues, Amazon EventBridge
- Transactional outbox pattern, microservices.io
- Message sessions, Azure Service Bus
- Duplicate detection, Azure Service Bus
- Dead-letter queues, Azure Service Bus
- Apache Kafka introduction
- CloudEvents specification
- Timeouts, retries and backoff with jitter, AWS Builders' Library
- Retry pattern, Azure Architecture Center
- RFC 6585: Additional HTTP Status Codes
- Working with webhooks in Dynamics 365 Business Central
- Best practices for data entities, Dynamics 365 Finance and Operations
- Internal IDs, external IDs and references, Oracle NetSuite Help
- Item resource type, Dynamics 365 Business Central API v2.0
Where to go from here
Frequently asked questions
What is idempotency in an ERP to PIM integration?
Idempotency means processing the same message more than once has the same effect as processing it once. In an ERP to PIM integration, the consumer stores a key built from the ERP record key and the event ID, and discards any message whose key it has already applied. This prevents duplicate variants, relations and asset links after retries or replays.
How do I stop old ERP events from overwriting newer data in the PIM?
Store a watermark per SKU containing the source change timestamp of the last applied change. Discard any incoming event whose source timestamp is older than or equal to the watermark, and log it as stale. Combine this with partitioning by SKU so that only one worker processes a given SKU at a time.
Does Kafka or Azure Service Bus guarantee message order?
Both can preserve order per key, as long as the Kafka partition count stays fixed and the Service Bus namespace is on the Standard or Premium tier. Kafka writes events with the same key to the same partition and consumers read each partition in order. Azure Service Bus sessions lock all messages with one session ID to a single receiver. Neither corrects events that were published in the wrong order, so a timestamp watermark is still needed.
What should happen when an ERP to PIM message fails?
Transient failures such as throttling or timeouts should be retried with exponential backoff and jitter, honoring any Retry-After header. Permanent failures such as validation errors should go to a dead-letter queue immediately, with the full payload and the reason. An administrator fixes the cause and replays the message through the same gates.
How long should I keep idempotency keys?
Keep them at least as long as any message could be retried or replayed, which includes the retention period of your dead-letter queue and any replay window you offer administrators. Many teams keep the latest key and watermark per SKU indefinitely, because that record is small and also serves the ordering check.
Diagnostic
Do you actually need a PIM?
Run the complexity index before you budget software or hire an SI.
Budget
Model a first-pass TCO
Translate catalog shape into a three-year cost range in under ten minutes.
