DevHuzaifa's Portfolio
•3 min read•Updated Oct 31, 2026

Data Pipeline Idempotency

Make retries safe with stable event identities, scoped uniqueness, atomic writes, and replayable partitions. Understand the boundary of exactly-once processing claims.

#System Design#Data Engineering

A worker inserts a batch and loses its connection before receiving the success response. Did the database commit? The scheduler cannot know from the timeout alone. Retrying is necessary, but a second blind insert can double the result.

An idempotent pipeline uses a stable event identity, commits an atomic destination write, and advances its cursor after the effect is durable.

Idempotency means repeating an operation with the same identity and intended input has the same intended effect. It does not mean a record is physically processed only once. State the effect and its scope before claiming that a pipeline is safe to retry.

Delivery and Effects Are Different Guarantees

At-most-once delivery can lose work; at-least-once delivery can repeat it. Exactly-once claims depend on the system boundary. Kafka transactions can coordinate supported Kafka operations, but writing to an external database or calling an API requires cooperation at that destination. A broker setting alone cannot make every external effect exactly once.

Apache Kafka delivery semantics

Step 1: Choose a Stable Identity

Use the source’s event ID, a change-log position, or another identifier that remains unchanged on retry. Scope it by source and tenant where needed. A new random UUID generated on each attempt identifies the attempt, not the business event.

example.sql
-- PostgreSQL example for immutable events.
create table processed_events (
    source text not null,
    event_id text not null,
    payload_hash text not null,
    primary key (source, event_id)
);

insert into processed_events (source, event_id, payload_hash)
values (:source, :event_id, :payload_hash)
on conflict (source, event_id) do nothing
returning event_id;

The unique constraint arbitrates concurrent attempts. If no row is returned, verify that the stored payload hash matches the retry. Reusing an immutable event ID with a different payload should produce a conflict or a documented correction path, not silently discard new information.

PostgreSQL INSERT and ON CONFLICT

Step 2: Commit the Receipt and Effect Together

python
# Transactional pseudocode; db is an application-specific adapter.
with db.transaction():
    inserted = db.try_insert_receipt(event.key, event.payload_hash)
    if inserted:
        db.apply_business_effect(event)
    else:
        db.assert_same_payload(event.key, event.payload_hash)
# Only acknowledge the source after this transaction commits.

The receipt and effect must use the same transactional destination for this contract. If the process crashes after commit but before acknowledgment, the source may replay the event and the existing receipt absorbs it. If it fails before commit, both operations roll back and the retry can apply them.

Updates Need Version Rules

Deduplication by event ID works for immutable events. A current-state table receiving corrections needs a business key and a source version or ordering rule. An upsert that blindly overwrites a row can let an older retry replace a newer value. Compare the source version atomically, including a deterministic tie policy.

For batch outputs, replacing a partition from a stable input snapshot can be simpler than deduplicating individual aggregate increments. Preserve the input range and transformation version. Repeatedly adding sum(batch) to yesterday’s total is not idempotent unless applying that batch is itself tracked atomically.

External Side Effects Need Their Own Contract

A database receipt cannot atomically cover an unrelated email or payment API. Use a supported provider idempotency key, an outbox with a retrying dispatcher, or an explicit reconciliation process. Document how long deduplication records and provider keys remain valid relative to the maximum replay horizon.

Test the Uncertain Outcome

Inject a failure before commit, after commit, and before source acknowledgment. Test two concurrent copies, a changed payload under the same key, out-of-order updates, and a replay older than your retention window. Monitor conflicts and duplicate deliveries separately: a duplicate that is safely absorbed is evidence that the design is doing its job.

Related: Handling Late-Arriving Data

Related: Commit First, Notify Later

Data Pipeline Idempotency: Safe Retries and Guarantees | Articles | Muhammad Huzaifa