Bulk import stops midway with a duplicate phone number—should the records that already succeeded be rolled back or kept for the rest of the import?
If a bulk import hits a unique key conflict halfway through, do not default to rolling back the whole batch, and do not simply skip the error. First check whether this batch is one overall voucher: reconciliation statements, settlement statements, and bulk write-offs are suitable for full-batch rollback; independent records such as customers, products, and stores are better handled with pre-validation, skipping conflicting rows, and exporting a failure list. Based on common 2026 delivery experience, for independent records, skip plus failure list usually means less operational rework, but the prerequisite is that failure details and batch numbers are defined clearly in advance; if an overall voucher partially succeeds, later reconciliation becomes more troublesome.
1. A unique key conflict in bulk import is not the same as an error from a single-record API
A unique key conflict occurs when a database unique index finds a duplicate value during insert or update. When a single-record API encounters it, the caller receives an error code, changes one record, and resubmits; a bulk import carries hundreds to tens of thousands of rows in one request, so failure handling affects transaction boundaries, lock hold time, error location, and operational rework at the same time. Looping the single-record logic directly often results in either the whole batch stopping at the first error or one transaction per row, causing locks to be released and acquired frequently.
A common project case: the customer-provided historical list contains duplicate phone numbers, the developer only implemented row-by-row inserts, a conflict is reported midway, a batch has already been committed, and operations does not know which rows succeeded or failed, so the entire batch must be redone. The cost here is not that the code is hard to write; it is reconciliation and rework. When delivering this type of import, usually confirm with operations which fields the failure list needs before defining transaction boundaries.
- Single-record API: errors return immediately, and the caller changes only one record.
- Bulk import: errors must be located to the row, and successes and failures must be counted separately.
- Transaction boundary: a single record can use one transaction per record; bulk imports need to be split by batch.
- Operations perspective: a failure list is needed, not just an “import failed” message.
2. Three common handling strategies—first check whether the batch is one overall voucher
There are three common failure-handling approaches for bulk imports: full-batch rollback, skip errors and continue, and pre-validation followed by batch submission. They are not a matter of which is more advanced; they correspond to different business semantics and rework costs. In 2026 project delivery practice, basic-data imports more commonly use pre-validation plus skip plus failure list, while voucher imports more commonly use full-batch rollback.
- Full-batch rollback: low implementation cost, large transaction scope; suitable for overall vouchers such as reconciliation statements and settlement statements; after failure, operations reimports the whole batch, and the experience range for rework is half a day to one day.
- Skip errors and continue: medium implementation cost, requires recording failed rows; suitable for independent records such as products, customers, and stores; operations fixes rows according to the list, usually one round of revision, with rework of about half a day to one day.
- Pre-validation then batch submission: higher implementation cost, one extra validation query; suitable for historical data with tens of thousands of rows or a high duplicate rate; development takes an extra 0.5–1 person-day, and rework is relatively lower.
Note that skipping errors does not mean swallowing errors. The system must return the success count, failure count, and failure details; otherwise operations can only guess. Full-batch rollback must also provide conflicting row numbers; otherwise reimporting the whole batch is still blind correction. What can be verified here is not a fixed number, but the typical ranges of the three approaches in implementation cost and rework cycle; during delivery review, recalibrate according to the project's actual row count and duplicate rate.
3. To decide between full-batch return and skip, ask four questions first
Rather than arguing full batch versus skip, ask four business questions. This framework is useful in delivery reviews because it puts the technical choice and business reconciliation responsibility on the same table, preventing development from unilaterally deciding on partial success.
- Is this batch one overall voucher? If yes, prefer full-batch rollback; if not, go to the next question.
- Do duplicate keys come from within the file or from existing database records? For duplicates within the file, run file-level pre-validation first; for duplicates in the database, then decide whether to update or skip.
- Can failed rows be retried independently? If they can be retried independently, skipping and outputting a list is suitable; if not, the full batch is safer.
- Does downstream require all successes before continuing? If downstream reconciliation depends on full success, do not use partial success.
If any of the four questions answers “must be full volume,” the strategy should lean toward rollback; if all four point to independent records, skip plus list is more suitable. The boundary is: if the import is only a one-off internal data fix, a complete failure detail table is not necessary, but a batch log should still be kept.
4. Delivery sites often get stuck on transaction size and failure lists
A common constraint at delivery sites: operations needs results the same day, the system cannot go down, and the historical file still contains duplicate phone numbers. The approach is to first run pre-validation for duplicates within the file, blocking obviously duplicate rows before they enter the database; submit the remaining data in batches with one transaction per 500–1,000 rows, and write conflicting rows to a failure list. The result is that among several thousand rows, dozens to two hundred conflicting rows are common; operations revises them in one round according to the list, with rework of about half a day to one day; the cost is maintaining an extra failure detail table and batch number, and subsequent reconciliation must be checked by batch.
Another common pitfall is recording conflicts only in application logs and not returning them to operations. Logs are for development; operations needs “which row, which field, and which existing record it conflicts with.” During delivery acceptance, check these three items first; missing any one means it fails. For the specific behavior of database unique indexes, check the official documentation of the database in use; do not judge from memory.
- Transaction too large: lock waits and rollback take longer, and the connection pool is easily exhausted.
- Errors only in logs: operations cannot fix them on their own, so rework goes back to development.
- Skipping without a batch number: later reconciliation does not know which records were imported in this run.
- Delete first, insert later to bypass conflicts: this briefly loses data and expands the lock scope.
- Automatically retry the whole batch after failure: duplicate keys still exist, and a retry storm can easily form.
5. Applicable scenarios and boundaries where it does not apply
Pre-validation plus skip plus failure list is suitable for independent records such as products, customers, stores, and employees, where operations can modify records according to the list; full-batch rollback is suitable for overall vouchers such as settlement statements, reconciliation statements, and bulk write-offs, where partial success actually increases reconciliation difficulty.
A complete import framework is not suitable for temporary data fixes, one-off data migrations, or internal configurations with only a few dozen rows; for these, scripts plus manual checks are simpler. Also, do not add automatic updates before the cause of duplicate keys is clear; otherwise records that should have been newly created may be overwritten.
To judge whether an import is well built, check four items: whether success and failure counts are returned, whether failure details can be downloaded, whether batches are traceable, and whether repeated imports are idempotent. Check item by item against the platform delivery acceptance checklist, rather than only whether this run succeeded.
Common questions
Will skipping error rows during import cause later reconciliation to mismatch?
Yes, so the skip strategy must also write a failure detail table recording row numbers, conflicting fields, and primary keys of existing records, and return the import batch number together with the success count; otherwise later reconciliation can only rely on manual guessing.
Is full-batch rollback always safer than skipping?
Not necessarily. Full-batch rollback is suitable for overall vouchers such as reconciliation statements and settlement statements; when basic data has only a few duplicates, returning the whole batch makes operations repeatedly revise the same file, which causes more rework within the typical range.
Can a unique key conflict be bypassed by deleting first and inserting later?
It is not recommended as a default. Delete first and insert later briefly loses data and also expands the lock scope; unless it is explicitly an overwrite import with a version number or update time as a fallback, it should go through an update or skip branch.
Should the import API enable transactions, and how large should they be?
Yes, but transaction boundaries should be split by batch, not one transaction for several thousand rows; the typical range is committing every 500–1,000 rows, with failed batches rolled back separately, to avoid long transactions holding connections and locks.
The duplicate is a phone number, but the user changed numbers—how do I tell whether it is the same person?
Do not rely only on phone number. A business key or external ID is needed for matching, with phone number only as an auxiliary field; otherwise, after a user changes numbers, they will be inserted repeatedly as a new record, making later merging more troublesome.
If you are stuck on this type of import rework, do not rush to change code. Clarify the two questions—“Is this batch one overall voucher?” and “Can failed rows be retried independently?”—then decide transaction boundaries and failure list fields. The applicable boundary is: for independent records where operations can modify by row, skip plus list saves rework; for overall vouchers or when downstream requires full success, full-batch rollback is safer.
-
In System Development, Is It Okay to Call APIs Inside a Transaction? When Database Connections Run Out, Everything Freezes
Date: Aug 29, 2026 Read: 77
-
Detail page images looked fine at launch, but days later customers see broken images—are private bucket signed links expiring?
Date: Nov 23, 2026 Read: 4
-
Order time shows 1970 in the order list but exports correctly to Excel: fix the page first or unify the API unit first?
Date: Nov 22, 2026 Read: 8
-
After the certificate is renewed and replaced, why does the client’s phone still show “not secure”—is the cache not refreshed?
Date: Nov 21, 2026 Read: 12
-
Invoice PDF only flashes when tapped in WeChat, but opens normally in a mobile browser—do we still need to change anything?
Date: Nov 20, 2026 Read: 17




