Tutorial

How to Design a Bulk Import Process for Customer Data

How to design a bulk import process for customer data that stages rows, validates and deduplicates them, and can be rolled back.

Designing a bulk import process for customer data comes down to four decisions: where rows land before anyone trusts them, which rules decide a row is valid, how duplicates are detected, and how a bad batch gets undone. Get those right and the import survives real files instead of corrupting the customer table.

What does a bulk import process need to do before it writes anything?

Before writing a record, a bulk import must stage the raw file, map its columns to database fields, validate every row against the application's rules, and report what will change. Nothing reaches the customer table until someone approves that report.

The instinct is to let the uploaded file write straight into the customer table and clean up afterwards. That works until the first file where a column was shifted one place left and 12,000 records now carry street addresses in the notes field. Staging costs one extra table and saves the clean-up.

A staging table is a scratch table that holds uploaded rows exactly as they arrived, with no format constraints applied. Each row keeps its original line number, so any record can be traced back to the file it came from.

Column mapping is the next step: deciding which file column feeds which database field. Save that decision as a mapping profile, a reusable record of the column-to-field correspondence for one file layout. Mapping a new layout typically takes an operator ten to twenty minutes; every later upload of the same layout should take seconds.

Validation is the set of rules that decide whether a row is fit to become a record. Run it against the same rules the application enforces at manual entry. If the form rejects a postcode without a space and the importer does not, the database slowly fills with records the interface cannot edit.

Finish with a dry run, meaning a full pass that writes nothing and produces a count of what would be created, changed, or rejected. That preview is the approval gate.

How should you validate and deduplicate customer rows?

Validate rows against the same rules the application enforces at data entry, then match each incoming row against existing customers on email, phone, and company name before deciding whether to insert, update, or skip it.

Deduplication is the process of finding incoming rows that already exist as records and deciding whether to merge, update, or skip them. Teams underestimate it. In a typical export from a legacy system or a pile of sales spreadsheets, roughly 5 to 15 percent of rows turn out to duplicate records already in the database, and another 2 to 5 percent fail basic validation. Plan the review step for those numbers, not for zero.

No single field identifies a customer reliably. Email is the strongest signal but misses contacts created by phone. Company name alone produces false matches across franchises. Match on several keys and score the result. Phone numbers should be normalised to E.164, a format that stores the country code and drops local formatting, before any comparison happens.

Match keyWhat it catchesWhere it fails
Email, trimmed and lowercasedMost true duplicates between systemsShared inboxes such as info@ that several contacts legitimately use
Phone in international formatDuplicates where the email has changedSwitchboard numbers shared across a whole site
Company name plus postcodeAccount-level duplicatesFranchises and sister sites with near-identical names
External ID from the source systemRe-imports of the same file, reliablyNothing, if the source ID is stable; useless if the export does not carry one

An upsert is a database operation that inserts a row when no match exists and updates the existing one when it does. Upserts on email plus normalised phone cover most cases, with a manual review queue for weak matches, meaning scores above the junk threshold but below the auto-merge threshold. Set both thresholds deliberately, and log every automatic merge so it can be reversed.

One more property is worth designing in: an import should be idempotent, meaning that running the same file twice produces the same result rather than two sets of records. The external ID key above is usually how you get there.

What happens when a row fails validation?

A failed row must not abort the batch or vanish silently. It gets parked with its original values, the rule it broke, and its line number, so an operator can fix the file and re-upload only the rejects.

Partial success is the correct default. An import of 40,000 rows where 600 fail should commit the 39,400 valid records and hand back a rejects file. All-or-nothing imports sound safer, but in practice they push operators to disable validation just to get the batch through.

The rejects file should carry the original columns plus three additions:

  1. The line number in the uploaded file.
  2. The field that failed and the rule it broke.
  3. A suggested correction where the system can infer one, such as a trimmed trailing space or a missing country code.

That third item is what makes re-upload practical. Without it, an operator is comparing two spreadsheets by eye at six in the evening.

How do you roll back a bulk import that went wrong?

Give every import its own batch identifier written onto each affected record, then rollback is a single filtered delete or restore of the previous values. Without that tag, undoing a bad import becomes manual work across thousands of rows.

A batch identifier is a value, usually a short code plus a timestamp, stored as a column on every record the import touched. It costs one column and turns "which records did the Tuesday import create" into a one-line query. Store the previous field values as well, at least for fields the import can overwrite, so an update can be reverted rather than only deleted.

For anything above roughly 5,000 rows, run the import as a background job, a process that runs outside the user's browser session and reports progress separately. Chunk it into transactions of a few hundred to a few thousand rows. A transaction is a unit of work that commits completely or not at all. One transaction covering 50,000 rows holds locks for the whole run and fails as a block; 100 transactions of 500 rows fail one at a time and let the operator resume.

What should the import screen show the operator?

The import screen should show a preview of the first twenty parsed rows, a count of valid, duplicate, and rejected records, and an explicit confirm step. Operators need to see the damage before it happens, not after.

Previews catch the class of error that validation cannot: the file that parses cleanly but has the wrong column in the wrong place, or dates that read as American when the operator meant European. Twenty rows is enough for someone to notice the surnames sitting in the first name column.

Show a running count during execution and a permanent link to the batch afterwards. If a support ticket arrives three weeks later asking why a customer's address changed, the batch record answers it in seconds.

Build order and rough effort

If you are commissioning this rather than building it, the sequence below keeps the risky parts early.

  1. Staging table and file parser. Roughly 2 to 4 days.
  2. Column mapping with saved profiles. Roughly 3 to 5 days.
  3. Validation layer reusing the application's existing rules. Roughly 3 to 5 days.
  4. Deduplication and match scoring. Roughly 1 to 2 weeks, and the piece most likely to need tuning once real data arrives.
  5. Commit, batch identifier, and rollback. Roughly 3 to 5 days.
  6. Review screen and rejects handling. Roughly 4 to 6 days.

A first usable version typically lands in three to five weeks for a single entity such as customers. Importing related entities, customers plus their addresses and contracts for example, usually takes two to three times that, because ordering and rollback now have dependencies.

If the import is part of a wider CRM build, design the staging layer as reusable infrastructure rather than a script for one file. The second and third entities will reuse most of it.

Frequently asked questions

How long does it take to build a bulk import feature?

A single-entity import for customer records typically takes three to five weeks of development effort, covering staging, mapping, validation, deduplication, commit, and a review screen. Importing related entities such as addresses and contracts usually takes two to three times longer, because the order of operations and the rollback path gain dependencies.

Should a bulk import insert new customers or update existing ones?

Most customer imports should do both, using an upsert that inserts when no match exists and updates when one does. Match on email plus a normalised phone number, and route weak matches to a human review queue rather than merging them automatically.

How many rows can a bulk import handle at once?

Row count matters less than how the work is chunked. Above roughly 5,000 rows, run the import as a background job and commit in transactions of a few hundred to a few thousand rows so a failure can resume rather than restart. A single transaction for 50,000 rows holds locks for the whole run and fails as one block.

How do you test a bulk import before running it on real data?

Build a set of deliberately messy test files: missing columns, shifted columns, mixed date formats, duplicate rows, and phone numbers with inconsistent country codes. Run each through the dry run and confirm the validation report catches what it should. This usually takes a day or two of work and prevents the failures that would otherwise surface during a live migration.

Back to blog