How to keep workflow retries from creating duplicate records

Design a retry that can safely repeat an intake or billing step, with stable IDs and a clear check for partial completion.

A retry should give a workflow another chance to finish without creating another copy of the work. Give the intended action a stable identity, make record creation safe when the same action arrives twice, and verify what happened before trying again after an uncertain response. These rules matter any time an integration can repeat delivery or a person can resubmit a request.

Define what a duplicate means for the business

Start with the object people have to correct. Two photos of the same delivery can be useful evidence. Two job cost receipts for the same signed delivery may overstate received quantities. Conversely, two deliveries against the same purchase order can be legitimate and need separate receipt records. Ask what combination of identifiers distinguishes one intended action from another. Document how partial deliveries, corrections and repeated customer requests differ.

Separate the identifier of the incoming message from the identity of the requested effect. A provider may give a unique identifier for each event, which helps recognize redelivery of the same message. Several messages can still refer to the same intended write. Stripe’s webhook documentation describes duplicate delivery and explains that delivery order is not guaranteed. It also distinguishes cases where distinct event objects represent the same underlying object and event type. Apply the equivalent rules for your provider and define the business action independently.

Decide what should happen when the data under an existing key changes. An exact repeat can reuse the first confirmed result. Different quantities under the same delivery key may indicate a correction or a data mismatch. Route it for review or process it through the authorized correction path. If any incoming payload under that key silently overwrites the original, retries can damage existing work even when record counts look correct.

Worked example for a signed material delivery

Imagine a contractor’s field form sends a signed delivery receipt to the job cost system. The request represents a particular vendor docket on PO-77. The job cost system creates its receipt and responds, but the response is lost before the field application sees it. The form appears to be waiting, and the integration later retries. Without a guard, the same delivery could be recorded twice while only one signed docket exists.

First assign a stable action key, such as the operation type plus the unique approved receipt ID the form retained. Include the job or tenant where needed to separate keys across scopes. Capture the supplier docket and purchase order as business evidence, with validation for the uses your suppliers support. Avoid making the transport attempt time part of the key. It changes on every retry. Equally, avoid a key like “PO-77” alone because another legitimate delivery still needs its own receipt.

At the destination, prefer a supported external ID with uniqueness enforcement or a documented idempotent operation. A database-backed implementation can enforce a unique operation key and commit the state record consistently with the write when both are in the same transaction. Two workers might receive the same action at nearly the same moment. A search followed by an unguarded create offers no guarantee that either search sees the other worker’s record. Establish the guarantee where the destination records the effect.

Keep the effect identifier and outcome. A successful duplicate can return the existing job cost receipt ID and its status. If the first attempt is running, a duplicate can wait or return a pending result according to the workflow’s interface. If it is uncertain whether the first request reached the destination, look up the approved external ID before sending another create. Keep uncertainty visible to an operator instead of treating every timeout as either success or failure.

Make retries specific to failure type

A rate limit or temporary network error may justify retrying with backoff and a finite budget. Respect documented retry intervals and make it possible to see attempts and the last response. A malformed payload or a vendor record that does not exist needs correction. Repeated delivery will not fix those conditions on its own. An operation where the system cannot tell whether the first write succeeded needs reconciliation against the destination.

For a separate downstream system, a local record that says a worker started does not prove that the external write happened. An external success followed by a local crash creates the same ambiguity as a lost response. Where supported, give the external call the stable key and reconcile before changing the local result. Where unsupported, use the best deterministic reference available, design a queue for uncertain outcomes, and require a reviewer before a second commitment. The cost of this additional check is preferable where another write could authorize spend or distort a report.

Think about retention for keys. A key stored for too short a time can expire before an event is replayed. Keeping all request bodies indefinitely can expose information and raise storage and privacy issues. Store the minimum reference, status and resolution needed to handle the longest relevant retry or manual replay window. Document how an authorized historical migration will be identified and processed.

Copy this retry specification into your workflow design

Write one row for each distinct external effect. A single workflow might create a receipt, attach a document and notify the office. Give each effect its own rule if one succeeds while another fails.

  • Intent and identity. Record the approved action, field or record key and source evidence. Say which changes produce a valid new action and when a different payload needs review.
  • Durable guard. Name the location and constraint that prevent duplicates under simultaneous attempts. Specify whether the destination honors the key and for how long.
  • Outcome and response. Store the destination ID and what staff see for a pending, completed, rejected or uncertain operation. State how to find the work without guessing whether it posted.
  • Retry policy. Describe temporary versus permanent errors, delay, limit and escalation. Identify the operator who may replay and the checks required before doing so.
  • Correction and reconciliation. Define who can resolve a mismatch and how a reversal or amendment links to the original. Keep one authoritative record of what was ultimately approved.

A design may require more than one check. For example, deduplicating events prevents the same notification from being processed repeatedly. Deduplicating business effects prevents a later separately generated event from creating a second record. Use both where your sources make both situations possible. Also protect against older updates that arrive after a newer correction. A newer revision should not disappear merely because a delayed delivery was eventually received.

Verify a retry under real failure shapes

In an isolated environment, provide the same input twice. Then submit it concurrently and check the count and IDs in the destination. Simulate a saved receipt with a lost response, a worker interruption during processing and a timeout that never reached the destination. Verify that the path for each one yields a single receipt or an explicitly assigned exception. Test an intentional second pallet against the same order to prove the key does not suppress legitimate work.

Finally send a different payload using a completed action key and verify that it is handled as a conflict or an authorized correction. Check the history for actor, source reference, first attempt, last attempt and eventual disposition. Confirm that staff can explain why the job cost system contains the final quantity. Monitor unresolved ambiguous attempts and duplicate corrections after rollout. These observations are more useful than a dashboard that counts retries without distinguishing their outcomes.

Bring an anonymized duplicate and its event history to an Operations Review. Blackwing can help design the acceptance tests through its systems implementation service.

Back to blog