← ALL PROBLEMS
Data & Analytics / IDEMPOTENT INGESTION

How to Stop Duplicate Records When Data Pipelines Retry

Design retry-safe ingestion with stable keys, deterministic batch handling and idempotent upserts instead of relying on exactly-once assumptions.

Problem-first engineeringPractical diagnosticsProduction-minded solutions
01 / THE REAL-WORLD SCENARIO

What is actually going wrong?

Retries are essential for resilient pipelines, but a retry can replay records after a timeout where the source write succeeded and the orchestrator never received confirmation.

Symptoms teams commonly notice

  • The same business event appears multiple times
  • Counts increase after a failed-and-retried pipeline run
  • A timeout is followed by a successful retry and doubled totals
  • Different source extracts contain overlapping records
02 / ROOT-CAUSE ANALYSIS

Why this problem happens

Use evidence to narrow the failure domain before applying a fix.

  • 01The ingestion process appends every attempt without a stable event key
  • 02A run can partially commit before orchestration reports failure
  • 03Deduplication uses a non-unique field or a changing timestamp
  • 04Overlapping extraction windows are not reconciled
  • 03 / VISUAL 01 — ARCHITECTURE EXPLORER

    Explore the system flow

    Select a stage to see what should happen and what evidence to inspect.

    SELECTED STAGE

    Source event

    Stable event ID / business key

    04 / SOLUTION DESIGN

    How to solve it reliably

    A production solution should address the root cause, make failures observable and support safe recovery.

    1. 01
      Identify a stable business key or event ID and document its uniqueness scope.
    2. 02
      Persist a batch ID and source offset so each attempt can be traced and replayed safely.
    3. 03
      Land raw data append-only, then deduplicate deterministically in a curated layer.
    4. 04
      Use an upsert operation such as Delta MERGE with a deterministic source record per key.
    5. 05
      Reconcile inserted, updated, rejected and duplicate counts; retain rejected records for investigation.
    IMPLEMENTATION EXAMPLE
    -- Delta Lake pattern: deduplicate the incoming batch first
    CREATE OR REPLACE TEMP VIEW source_dedup AS
    SELECT * FROM (
      SELECT *, ROW_NUMBER() OVER (
        PARTITION BY order_id, line_id
        ORDER BY source_updated_at DESC, ingest_timestamp DESC
      ) AS rn
      FROM incoming_orders
    ) s WHERE rn = 1;
    
    MERGE INTO curated_orders AS t
    USING source_dedup AS s
    ON t.order_id = s.order_id AND t.line_id = s.line_id
    WHEN MATCHED AND s.source_updated_at > t.source_updated_at
      THEN UPDATE SET *
    WHEN NOT MATCHED THEN INSERT *;

    Illustrative starting point. Validate identifiers, data types, security and platform-specific syntax in your environment before production use.

    05 / VISUAL 02 — DIAGNOSTIC SIMULATOR

    Find the likely failure area

    Choose the symptom closest to what you observe. This guided diagnostic suggests where to investigate first; it does not replace environment-specific testing.

    FIRST INVESTIGATION
    ⌁

    Duplicates only after retries

    Inspect partial commits and replay behaviour for the failed run ID.

    06 / VISUAL 03 — IMPLEMENTATION WALKTHROUGH

    Turn the fix into an operating practice

    Follow the stages in order. Each step creates evidence for the next one.

    IMPLEMENTATION STAGE 01

    Choose the idempotency key

    Use source event ID or a composite business key with documented semantics.

    07 / PREVENTION CHECKLIST

    Keep the problem from returning

    • Choose the idempotency key: Use source event ID or a composite business key with documented semantics.
    • Separate raw from curated: Keep immutable input and process it into a trusted target.
    • Make writes repeatable: Use deterministic deduplication and transactional upserts.
    • Test replay scenarios: Run the same batch twice and prove the curated result is unchanged.
    RELATED TIERSHIFT CAPABILITIES

    Where we can help

    LET'S SOLVE THE RIGHT PROBLEM

    Dealing with this challenge in your environment?

    Share the symptoms, constraints and outcome you need. We can help scope a practical technical approach.

    Talk to TierShift →