DaletGuard supports civilians affected by armed conflict through Families Beyond War. All sides, no political affiliation. About our humanitarian work

Idempotent Accounting Sync, Explained

Every accounting pipeline runs the same work several times, and an idempotent accounting sync makes each single repeat completely harmless. A timeout fires after the provider answered, two schedules overlap, or someone presses the Run sync button twice by mistake. The sync is idempotent when each repeat leaves your data exactly as a single run would, with no doubled invoices. This article covers the stable upsert key, history that ignores all identical replays, keyed write queues and clear job limits. DaletBook is the worked example, because its pull and write paths follow all of these rules in the code itself.

Illustration of scale, eye, folder for idempotent accounting sync
Key takeaway

Make every repeat harmless. Key each upsert by tenant, platform and provider record, write history and current state in one transaction, give each queued write its own idempotency key, and allow one running job per connection and direction.

Why do duplicate runs come from the normal job recovery?

Also, before you design an idempotent accounting sync, list every way a run can repeat. Duplicates rarely come from one bad line of code. In addition, they come from normal recovery behavior. Also, the next step builds on your upsert key and adds an example.

Moreover, a network call times out just after the provider sent its response. In addition, your worker retries, and the same page of bills arrives again. Besides, a deploy restarts a worker halfway through a job, and the job starts over. Good notes on the idempotent accounting sync help the next person on the team.

Notably, each rule for the idempotent accounting sync is written down and dated. Each exception to the upsert key is recorded before it is approved.

Likewise, each of these events is healthy on its own. Retries are how you survive flaky networks, and schedules are how data stays fresh. Trouble starts only when storage treats every arrival as new. Then a retry turns into a second invoice, and a report total drifts away from the ledger.

Indeed, so the fix is not fewer retries. Instead, you make repeats harmless. Run the sync once or five times, and the stored state ends up the same. In fact, our trainers cover our idempotent accounting sync with practice records.

How do you choose the key for a repeat safe sync?

Furthermore, every upsert needs a key that names one real record. The provider's own ID is the obvious start, yet it is not enough alone. Specifically, two tenants can hold invoices with the same provider ID. One tenant can also connect two platforms whose ID ranges overlap.

DaletBook keys each upsert by three values, which are the tenant, the source platform and the provider reference. Overall, the write is one INSERT ON CONFLICT statement on that key. A new record is inserted, and a known record is updated where it sits. Also, a replayed pull lands on the same rows and adds no new ones.

DaletBook job status screen
For example, every sync job closes as succeeded, partial or failed.

Why must the key be scoped by tenant first of all?

Pick the fields with care, because the key outlives the code. Avoid values that users can edit, such as invoice numbers or display names. Prefer the internal ID that the provider assigns and never reuses. Then scope it by tenant first, so one customer's records can never collide with another's.

In addition, the same keyed upsert sits behind every scheduled or on-demand sync job in DaletBook. Teams often ask how the idempotent accounting sync works in practice. A reviewer will want to see your idempotent accounting sync written down.

Moreover, a reviewer will want to see your upsert key written down. People new to the topic should learn your upsert key first. Keep the idempotent accounting sync simple, and test it on a small case first.

Why must the history ignore the replays that are identical?

Current state is only half the story. Besides, many teams also keep a history of what each provider returned, and when. That history follows the same rule. Otherwise a retry looks like a real change to anyone who reads it later.

Notably, in DaletBook, every accepted pull first appends a sanitized generation to a permanent ledger. The upsert of current state follows inside the same tenant transaction. Likewise, if the provider sends new values, the new generation joins an ordered correction chain. If it sends identical values, the replay is idempotent, and no new generation appears.

Plain language helps when you describe the idempotency key. Indeed, the notes on your idempotency key are reviewed by a second person. Teams often ask how the idempotent accounting sync works in practice.

Five steps that turn an accepted pull into sanitized, chained and exportable evidence
Each accepted pull becomes a sanitized generation in an ordered chain.

In fact, an auditor or analyst sees one entry per real change, and not one per retry. Credentials, session material, private keys and card data are stripped out before storage. Furthermore, the page on the permanent evidence ledger covers the chain, holds and exports. Questions about the idempotent accounting sync are welcome in our classes.

How does an idempotency key guard each write in the queue?

Writes carry a higher risk than reads. Specifically, a repeated pull only rewrites your own tables. A repeated write can create a second invoice in your customer's ledger, where you cannot quietly undo it. People new to the topic should learn your idempotent accounting sync first.

Check the one running job again after each change at the provider.

DaletBook places every create, update and void in an outbox first. Overall, each entry holds the entity type, the operation, the payload and an idempotency key. Updates and voids also need the provider record reference, so the target is never a guess. Credentials are never stored with the entry.

Also, the connector's declared capabilities act as a gate. A write that fails this check records nothing and never reaches the provider. In addition, after that, each entry tracks its status, its attempts, the next available time and the last error.

The default limit is five attempts. Moreover, when an entry fails, you retry that same entry, and its key comes along. Our trainers cover our one running job with practice records.

Provider support for idempotency keys varies, so check each provider's write documentation before you lean on it. Besides, for the review step before confirmation, see how queued writes are reviewed. Keep the idempotent accounting sync simple, and test it on a small case first. Plain language helps when you describe the upsert key.

Questions about each idempotency key are welcome in our classes. Keep the one running job simple, and test it on a small case first.

DaletBook provider catalogue entry screen
For example, the provider catalogue shows what each connector reads.

Notably, even an idempotent accounting sync can go wrong when two jobs pull the same connection at once. The two jobs race, and the last commit wins, even if it holds older data. Likewise, a simple lock removes the race before it starts. Check the idempotent accounting sync again after each change at the provider.

DaletBook lets only one job run per connection and direction. Indeed, a second trigger gets a 409 response that says a run is already active. Every job starts in the running state and closes as succeeded, partial or failed. Plain language helps when you describe your idempotent accounting sync.

Failures follow the same discipline. Connection-level problems stop the run, namely auth_expired, host_down and rate_limited. In fact, a data_error on one entity lets the other entities continue, and the job ends as partial. Because the upsert is keyed, the next run pulls again, and rows that already arrived are matched.

Good notes on the one running job help the next person on the team. Changes to our idempotent accounting sync are logged with a reason.

The nightly sync use case shows this pairing of a lock and a keyed upsert on a fixed timetable. Furthermore, this part of the page shows how the idempotent accounting sync fits the whole flow. Our trainers cover our upsert key with practice records. Teams often ask how your one running job works in practice.

How do you test the sync before the launch day?

Rules on paper do not prove behavior. Run the checks below against a sandbox for each provider you plan to support. Nothing about the idempotent accounting sync needs a special tool. Questions about each upsert key are welcome in our classes.

Specifically, many reviewers begin with your idempotency key when they audit a flow. The next step builds on your idempotency key and adds an example. Overall, this part of the page shows how our one running job fits the whole flow.

  • Replay a full pull, and confirm that the row counts match exactly.
  • Edit one record at the provider, pull again, and confirm one new history entry.
  • Stop a job midway, start it again, and look for duplicate rows.
  • Start two runs on one connection, and confirm that the second is refused.

Force a write error, retry the entry and confirm that one record exists at the provider. The connector tests in the repository use mocked HTTP responses, so your own sandbox is the final proof. Also, a reviewer will want to see your idempotent accounting sync written down. People new to the topic should learn your idempotency key first.

Illustration for Idempotent Accounting Sync, Explained

Start with the key, then prove the replay of a sync

Idempotency is a choice you make early. It is not a patch you add later. Pick a stable key, scope it by tenant and platform, and write history and state in one transaction.

Then guard writes with a keyed outbox, and allow one running job per direction. In addition, many reviewers begin with each idempotent accounting sync when they audit a flow.

Retries also meet provider limits, so the next topic is rate limits and pagination. Records that vanish at the provider raise a separate problem, covered in handling deleted accounting records. The pillar guide on unified accounting APIs ties all of these threads together. Start small when you set up the idempotent accounting sync.

A diagram of 3 connected steps, each with a small drawing: Upsert key, Idempotency key, One running job.

Questions and answers on this topic from the product team

Does a replay safe pull need a database transaction?

It helps a great deal. If history and current state are written in separate steps, a crash between them leaves the two out of step. DaletBook writes both in one tenant transaction, so either both changes commit or neither does.

How many attempts does DaletBook make on a queued accounting write?

Each outbox entry tracks its attempts, with a default maximum of five. The entry records its status, the next available time and the last error. An operator can retry a failed entry, and it keeps its payload and idempotency key.

See how DaletBook fits the providers your team uses today

Book a short meeting for a walkthrough with your own providers in mind, or join an in-person class to learn the method first.