When an ERP sync fails halfway, the safe retry is the hard part
Idempotency keys, a transactional outbox and three-way reconciliation keep a client's books matching to the last cent when the period closes.
In brief
- Duplicate journal entries usually come from a resend after a timeout, so the key must come from a business ID, not a random number.
- Write the transaction and the outbox event in the same database transaction, retry transient errors such as 429, and compensate only when retries keep failing.
- Reconciliation must distinguish money in transit (a timing difference) from money that is genuinely missing or wrong.
On the third day of the period close, the client’s chief accountant sends you a screenshot: the ERP holds two identical journal entries for the same payout, while the previous day’s payout is nowhere to be found. Your code never crashed. The log says “timeout, retrying”, then “success”.
This is a familiar situation for FDEs building accounting integrations for large clients. To a finance team, a duplicate journal entry is not a minor bug: a single figure that does not match is enough to stop them signing off the accounts.
You can build a slick sync demo in a week, but for a client to trust your system it has to stay correct through thousands of flaky network moments.
Three questions decide the quality of any ERP integration: can a transaction be lost, can it be recorded twice, and when something fails midway, what state are the books in? Add a fourth, the one the client actually cares about: how do you prove the two sides match?
Transactions lost before they reach the ERP
The first failure sits inside your own service. The service saves the transaction to its database and only then emits a “needs syncing” event. If the process dies between those two steps, the record exists but nobody tells the sync worker. Microsoft calls this the dual-write problem.
The fix is the Transactional Outbox: write the transaction and the event to an outbox table in the same database transaction. Microsoft’s architecture documentation states that when the business object and its event are saved in the same transaction, the system guarantees no data is lost.
The worker simply reads the outbox and pushes entries to the ERP, so whenever the process dies, there is no gap left.
Why does one retry create a second journal entry?
Back to the screenshot. Picture it: the worker sends a journal entry, the ERP posts it, but the response is lost on the way back. The worker sees a timeout and sends again. The ERP has no idea this is the same request, so it posts another entry.
Stripe solves this with idempotency keys. The client attaches a key to a create or update request, so if a connection error occurs you can resend without fear of creating a second object or applying an update twice.
In API v1, the server stores the first response for a key and returns exactly that response to every retry, even if the first response was a 500 error.
Stripe’s documentation adds two more details. The key is generated by the client, and it is deleted after at least 24 hours. Reusing a key with different parameters is rejected, to catch mistakes.
Those two details yield two rules. The key must be derived from a stable business ID (for example erp-journal:po_123), never from uuid4() on each send, because a random key makes a retry look like a new request.
And because keys expire, and not every ERP offers this mechanism, you cannot hand deduplication entirely to the ERP. You must keep your own mapping table from key to ERP record ID and, more importantly, write that row before the first send, not after the response arrives.
A payout sync worker, written correctly
Suppose you push payouts to NetSuite every night. According to Oracle’s documentation, when the concurrency limit is exceeded, NetSuite REST Web Services returns HTTP 429 with the code CONCURRENCY_LIMIT_EXCEEDED and the message “Concurrent request limit exceeded. Request blocked.”
Oracle advises resending the request, and the retry logic lives in your code. The snippet below uses a hypothetical erp wrapper with a function that looks up journal entries by external ID:
def sync_payout(payout_id):
key = f"erp-journal:{payout_id}" # from the business ID, not random
row = mapping.get(key)
if row and row.erp_id:
return row.erp_id # posting confirmed: do not resend
if row is None:
mapping.save_pending(key) # write "pending" BEFORE the first send
for attempt in range(6):
found = erp.find_by_external_id(key) # an earlier send may already have posted
if found:
mapping.confirm(key, found.id)
outbox.mark_done(payout_id)
return found.id
try:
resp = erp.post_journal(build_payload(payout_id),
external_id=key, idempotency_key=key)
except Timeout: # unknown whether the ERP posted it
sleep(min(2 ** attempt, 60) + random())
continue # next loop looks up again before sending
if resp.status == 429: # CONCURRENCY_LIMIT_EXCEEDED: transient error
sleep(min(2 ** attempt, 60) + random())
continue
resp.raise_for_status()
mapping.confirm(key, resp.id) # confirm the mapping before clearing the outbox
outbox.mark_done(payout_id)
return resp.id
alert_oncall(payout_id, key) # retries exhausted: hand over to a human
Run that night’s scenario through this code. Before sending, the worker has written a “pending” row for the key. The first send times out, but the ERP did in fact post the entry. The worker catches the Timeout exception, waits out the backoff and moves to the next loop.
On the next loop, the first action is not to resend but to ask the ERP whether an entry with this external ID already exists. It does, so the worker just confirms the mapping and stops. If the ERP supports idempotency, the same key adds another layer of protection, but the design does not depend on it.
The “pending” row also matters when the process dies outright and restarts three days later: the worker sees an unconfirmed row, so it always checks the ERP before sending. The one condition is that you store the key in a searchable external ID field on the journal entry, and you should agree that field with the client in the first week.
If step two fails, what happens to step one?
A real payout usually passes through several steps across several systems: create the revenue record, post the journal entry, mark it as paid. No ACID transaction can span both your platform and the ERP. The Saga pattern replaces it with a chain of local transactions: when a step fails, a series of compensating transactions undoes what the earlier steps did.
Sagas have the notion of a pivot transaction, the point of no return. Steps after the pivot must be retryable and idempotent so the saga always reaches its final state, even in the face of transient errors. In an ERP posting flow, the posted journal entry is usually the pivot.
The specific reason at each client is best treated as an assumption to verify: ask the chief accountant whether, when an entry is wrong, they edit it directly or must post a reversing entry. If it truly is the point of no return, after it the only way is forward.
Microsoft gives a very practical order of priority: retry transient errors first, stop and trigger compensation only when a step fails repeatedly or cannot recover, and some failures need an alert so a human can step in. The compensation step itself can fail, so it must be written as an idempotent command that can be rerun.
In accounting, the most important requirement is auditability. Microsoft requires that both the original operation and the compensating operation can be linked and audited end to end. Attach the same correlation ID to the original entry, the compensating entry and the logs, so an auditor can trace the whole chain with a single search.
Reconciliation is your proof, not extra work
A correct sync is still not enough, because the client needs to see evidence. Stripe’s bank reconciliation model is a good template: each payout is matched to its bank deposit through a shared reference key, then marked Reconciled or Unreconciled. Extend this model to three ways: platform, ERP and bank statement, all sharing one key.
The biggest trap is confusing timing differences with real errors. Stripe’s sample example notes that banks typically do not credit payouts on Sundays, so the amount cell for Sunday 4 February in the example is left blank.
If your report flags every such row as an error, the finance team will drown in false alarms and stop trusting the report.
| Category | Signal | Action |
|---|---|---|
| Matched | Present in all three, same amount | Nothing |
| Timing difference | Present on the platform and in the ERP, not yet credited by the bank | Wait, recheck after the settlement cycle |
| Real mismatch | One side missing past the deadline, or amounts differ | Open a ticket, trace by correlation ID |
Building it from scratch, in what order?
At a new client, the first task is to sit down with the chief accountant and ask which step is the point of no return, and how they correct mistakes. The answer tells you where the pivot is and what the compensation step must look like.
Next, set up the outbox in your database, define a key for each step based on business IDs, choose the external ID field in the ERP that will hold the key, then write a worker with retries and backoff for transient errors.
Only then come compensation and alerting. Reconciliation should run from the first week, not wait until period end: the three-category report above is the fastest way to catch design flaws before the client does.
The mistakes that cost the finance team’s trust
The most common mistake is generating a random key on every send, which defeats idempotency. Close behind is writing the mapping only after a successful response, so at the very moment of a timeout the table is empty. Next is treating every 429 or timeout as a failure and running compensation immediately, when it should have been retried first.
Two more. A compensation step that is not idempotent, so a rerun compensates twice. And one of communication: reporting a “mismatch” for every amount not yet in the bank. A client will remember one report full of false alarms longer than ten nights of smooth syncing.
How to describe this skill on a CV
A line reading “NetSuite integration” on a CV says almost nothing. Describe how you designed idempotent sync, handled partial failures and built three-way reconciliation, along with the number of period closes in which the client did not have to fix a single line by hand.
In interviews, the scenario “the ERP posted it but the response was lost” is a short story that shows you think about failure before it happens.
Next time someone says “just retry it”, ask them: retry with which key, and did you ask the ERP before sending again?
Was this article useful?
Thanks for the feedback!
6 sources
- Idempotent requests | Stripe API Reference
- Error Handling in REST Web Services (Oracle NetSuite Help)
- Saga Design Pattern - Azure Architecture Center | Microsoft Learn · 2025-02-25
- Compensating Transaction Pattern - Azure Architecture Center | Microsoft Learn · 2026-04-16
- Implement the Transactional Outbox Pattern by Using Azure Cosmos DB - Azure Architecture Center | Microsoft Learn · 2026-02-23
- Bank reconciliation | Stripe Documentation