Back to Blog
Integrations & systems

How to prevent duplicate records when connecting two systems through an API

A practical guide to preventing duplicate records in API integrations: establish record identity, make repeated requests safe, handle retries and test the workflow before launch.

Published 4 min read

An order shows up twice in an operations system. Staff cannot tell which row to update, and a report counts both as separate sales. The cause may be a routine timeout: the integration did not receive a response, so it sent the create request again.

Preventing duplicate records in API integrations takes more than searching for matching names. Two different problems need attention. The same operation might be delivered twice, or two systems might already hold representations of the same real-world entity under different IDs. The first calls for safe handling of repeated requests; the second calls for a reliable way to identify and link records. Without both, synchronization can spread errors across the workflow.

Decide what counts as the same record

Map the journey of one entity first. Consider an order created in an online store and copied into an internal tool. Which system creates it? Which system may change it? What happens when the order is corrected or cancelled? If ownership and update rules are unclear, a changed order can accidentally be treated as a new one.

Keep a stable source-system ID and record its relationship to the ID assigned by the destination. That mapping lets the integration check whether the order has already been created. If the destination supports a unique external ID, consider using it; otherwise, maintain a mapping table with a uniqueness constraint. Include the source system and, where relevant, the customer or account scope in the key. An ID that is unique within one account may not be unique across every account.

A name, email address or date is usually a poor substitute for a stable ID. These values can change, be missing or legitimately repeat. Historical records without shared identifiers may require carefully defined matching rules. Route uncertain matches to a person rather than automatically merging them: linking two distinct records can cause more damage than temporarily leaving a possible duplicate unresolved.

Make repeat requests safe

An integration may not know whether a request succeeded. A network error could occur after the destination created an order but before it returned confirmation. Blindly sending another create request risks making another record.

Design the operation so that repeating it with the same identity has the same logical outcome. If the destination API supports idempotency keys, reuse one stable key for retries of the same operation, rather than generating a new key each time. Check how long the destination retains those keys and what it does when a key is reused with different data. Another option is updating a resource addressed by a stable key, where the API contract allows it. If neither is available, check your mapping before creating and protect the local record against simultaneous attempts. A lookup alone will not prevent two workers from racing; use a uniqueness constraint or another concurrency control.

Keep record identity separate from operation identity. An order keeps its ID when its status changes, but each status change may need its own reference to avoid applying it twice. If events can arrive out of order, decide how versions or sequencing should be checked before applying an update.

Retry without burying failures

Classify errors before adding retries. A temporary service failure or rate limit may warrant another attempt after a delay. A missing required field needs correction, not an endless loop. For transient failures, use increasing delays, follow any retry guidance supplied by the API and set a point at which the item moves to review.

Log attempts with a correlation ID, the source entity, operation, outcome and error reason. Avoid logging credentials or unnecessary personal data. If failed items enter a queue, provide a controlled way to resume them once the cause is fixed while retaining the original idempotency key. Do not assume every conflict response means success: it might indicate an existing resource or a genuine data mismatch. Check the destination state before choosing what to do next.

Add periodic reconciliation as a second line of defence. Compare source records, ID mappings and destination results to identify missing or duplicated entries. Reconciliation does not replace safeguards on creation; it catches problems that still get through and gives the team a way to assign and resolve them.

Test the workflow before switching it on

Use representative test data and try creating the same record twice. Have two workers process it concurrently. Simulate a response lost after the destination creates the record. Include out-of-order updates, historical records without mappings and a partial failure in which creation succeeds but saving the local mapping fails. Verify not just the absence of extra rows but also that the integration can find the correct destination ID and continue.

Before enabling the full flow, review minimum access permissions, uniqueness constraints, error logs and the steps for pausing or reversing the integration. Start with a limited set of entities and observe how many operations create records, update them, retry or require review. Name the person responsible for ambiguous matches and establish how to correct errors without deleting valid information.

A useful first step is to pick one entity and write down its rules for identity, creation, updates and recovery after failure. If you want to check that design before production, you can review the proposed workflow with Cibercoding.

Topics

  • API Integrations
  • Idempotency
  • Software Architecture
  • Data Quality
  • Automation