Prompt
How do I retry failed data transfers without creating duplicates?
Latest observation
Oct 8, 2026
OpenAI APIWeb search: off
To retry failed data transfers without creating duplicates, use an idempotent transfer design. The core idea is: if the same transfer is attempted more than once, only one copy should be applied.
Practical ways to do that
-
Use a unique transfer ID
- Assign every transfer a stable, unique ID.
- Before applying a transfer, check whether that ID has already been processed.
- If yes, skip it; if no, process it and record it as completed.
-
Make writes idempotent
- Prefer operations like:
- Upserts (
INSERT ... ON CONFLICT DO UPDATE) - Replace-by-key
- Set state to final value
- Upserts (
- Avoid “blind append” unless duplicates are acceptable or deduplicated later.
- Prefer operations like:
-
Track transfer status
- Store states such as:
pendingin_progresssucceededfailed
- On retry, only pick up records that are
failedorpending. - Ensure only one worker can claim a transfer at a time.
- Store states such as:
-
Use a deduplication key
- If the source doesn’t provide a transfer ID, create one from the content and context:
- source system
- source record ID
- destination
- timestamp or version
- Store this key with a unique constraint.
- If the source doesn’t provide a transfer ID, create one from the content and context:
-
Make retries safe with atomic updates
- The “check then insert/update” step should be atomic.
- Use database transactions or uniqueness constraints to prevent race conditions.
-
Handle partial failures carefully
- If a transfer can fail halfway through, design it so rerunning it won’t double-apply side effects.
- Example: write data first, then mark the transfer complete only after success.
Example pattern
- Table
transfers:transfer_id(unique)statuspayload_hashattempt_count
Retry logic:
- Look up
transfer_id - If
status = succeeded, do nothing - If
status = failed, retry processing - When processing succeeds, update status to
succeeded
Best practice summary
- Always identify each transfer uniquely
- Store completion state
- Use database uniqueness or idempotent operations
- Retry only unfinished transfers
- Ensure processing can be safely repeated
If you want, I can also show:
- a database schema example
- a Python/JavaScript retry pattern
- or a message-queue approach for exactly-once-ish processing.
Brands