Scrivio Interview library
DesignPrincipal6 min read · updated 12 November 2026

Several teams build their own bulk import pipelines for partner files, each with different reliability and performance. What would you standardise, and what would you leave to teams?

I would standardise the hard, generic parts that every import needs and most teams get wrong: staging tables, COPY-based loading, validation stages, idempotent re-runs, error reporting and audit, delivered as a shared library or platform service, or an adopted tool such as Spring Batch, instead of each team's hand-written loops. Domain validation and mapping rules stay with the teams that understand the data. On top, we set limits on load windows and database resources so imports cannot hurt OLTP traffic, and we decide build versus buy from volume, the number of formats, compliance needs and the cost of operating it.

Why this question is asked

Partner file imports look simple, read a file and insert rows, so every team writes its own. A few years later the company has a dozen pipelines, each with its own way of failing: duplicates after a retry, silent row drops, imports that lock tables during peak hours. Interviewers ask this to see whether a senior engineer can draw the line between what a platform should own and what teams should keep. In this answer, we will see what goes wrong without a standard, choose the parts to standardise, decide how to deliver them, keep the right parts with teams, protect the database, and make the build versus buy decision.

1What Goes Wrong When Every Team Builds Its Own

The failures repeat across teams because the hard problems are the same everywhere. A file is retried after a timeout and half its rows are inserted twice, because the pipeline has no notion of 'this file was already loaded'. A malformed row stops the whole import at row 800,000 with an exception in the logs and no report the partner can use. An import inserts row by row through the ORM and takes hours, or runs as one huge transaction that holds locks and bloats the table. Nobody can answer an auditor's question about which file produced a given record.

None of these are domain problems. They are problems of moving data reliably, and solving them twelve times, each slightly differently, is waste and risk.

2The Parts Worth Standardising

A good import pipeline has the same stages regardless of the data. The file arrives and is registered with a checksum, so a second delivery of the same file is recognised. Rows are loaded quickly into a staging table, with COPY, without constraints, so loading never fails on bad data. Validation then runs in SQL and code over the staging rows, marking each row valid or rejected with a reason. Valid rows are merged into the target tables in batches with idempotent statements, and rejected rows go into an error report the partner can read. Every step writes an audit record.

SQL
-- Idempotent registration: the same file is never loaded twice
INSERT INTO import_files (partner_id, sha256, received_at, status)
VALUES (?, ?, now(), 'RECEIVED')
ON CONFLICT (partner_id, sha256) DO NOTHING; -- 0 rows: already seen, skip
-- Merge valid staging rows in batches, safe to re-run
INSERT INTO products (partner_id, sku, name, price)
SELECT partner_id, sku, name, price FROM staging_products
WHERE import_id = ? AND status = 'VALID' AND batch_no = ?
ON CONFLICT (partner_id, sku) DO UPDATE SET name = EXCLUDED.name, price = EXCLUDED.price;
Step throughA standard import pipeline
  1. Receive and registerchecksum, partner, idempotent file record
  2. Load to stagingCOPY, no constraints, fast
  3. Validategeneric checks + team's domain rules
  4. Merge in batchesidempotent upserts, small transactions
  5. Report and auditrejected rows with reasons, lineage per record

5 layers, from the top down. Step through them one at a time.

The platform owns every layer's mechanics; teams plug their rules into validation and mapping.

Notice that every step can be repeated without harm. Registration is a no-op for a known file, and the merge uses ON CONFLICT so re-running a batch gives the same result. That idempotency, the property that doing something twice has the same effect as doing it once, is what lets the pipeline retry automatically after any failure instead of needing a person to clean up.

3How to Deliver It

There are three realistic ways to give teams these parts. A shared library, for example a Spring Boot starter that provides the staging, COPY loading, merge and reporting steps, keeps imports inside each team's service and is cheap to start, but every team still operates its own jobs. A platform service that receives files and runs pipelines centrally takes operations away from teams, at the cost of a team that must run it and an interface for plugging in domain rules. Adopting an existing tool is the third way: Spring Batch already provides chunked processing, restartable jobs and job metadata, and commercial data integration products add connectors, scheduling and monitoring.

My usual choice is to build on Spring Batch through a shared library first, because it gives restartability and job history for free and fits the teams' stack, and to move towards a platform service only if the number of pipelines and the operational load justify a dedicated team.

4What Stays With the Teams

Standardising too much is also a failure: a central team that has to understand every partner's data becomes a bottleneck. So the line is drawn at meaning.

Who owns what
ConcernOwnerWhy
File registration, checksums, re-runsplatformidentical for every import
Staging and COPY loadingplatformperformance needs expertise
Format parsing (CSV, fixed width, XML)platform, extensiblefew formats, many users
Domain validation rulesteamneeds business knowledge
Field mapping to the domain modelteamchanges with the product
Error reports and audit trailplatformcompliance needs one standard
Mechanics central, meaning local.

The test is simple: if getting it wrong would be a bug in the domain, the team owns it; if getting it wrong would be a bug in moving data, the platform owns it.

5Protecting the OLTP Database

Imports share the database with customer traffic, so the standard includes limits. Large imports run in agreed load windows, outside peak hours. Each pipeline connects with its own database role that has a connection limit and a statement_timeout, so a runaway import cannot take every connection or run a query for an hour. Merges happen in small transactions, a few thousand rows each, with pauses if replica lag or database CPU crosses a threshold. Staging tables live in a separate schema and are truncated after each import, so they do not bloat the main tables. These rules are built into the shared code, so teams get them without having to remember them.

6Build Versus Buy

The decision depends on a few numbers. With five pipelines, two formats and modest volumes, a shared Spring Batch library is cheap and enough. With fifty partners, many formats, strict compliance requirements such as retention and lineage, and imports in the terabytes, a data integration product or a dedicated platform team may be cheaper than growing the library. The cost of operating it counts as much as the licence or the build: someone must upgrade, monitor and support whichever option we pick. I would write the decision down with those numbers, and revisit it when the number of pipelines or formats doubles.

7Follow-up questions

Why load into staging instead of directly into the target table?

Staging separates fast loading from validation. COPY into a constraint-free staging table never fails on bad data, so we can validate every row, report all errors at once and merge only valid rows. Loading directly would fail on the first bad row or require slow row-by-row inserts with error handling.

How do you migrate existing team pipelines?

Start with the pipelines that cause the most incidents, migrate them with the platform team's help, and make the shared library the only approved way for new pipelines. Old pipelines move as they need changes, not all at once.

Where does Spring Batch fit compared with COPY?

Spring Batch provides the job structure: chunking, restart from the last successful step and job history. Inside a step, the writer can use COPY or JDBC batching for speed. They complement each other rather than compete.

8Conclusion

In this answer, we saw that teams building their own import pipelines repeat the same reliability and performance mistakes. We standardise the generic parts, file registration, staging, COPY loading, validation stages, idempotent merges, error reports and audit, through a shared library built on Spring Batch or a platform service, and leave domain validation and mapping to the teams. Resource limits protect OLTP traffic, and the build versus buy decision rests on volume, formats, compliance needs and operating cost.

What to say in the interviewAbout 90 seconds aloud

Open with

I would standardise the parts that are about moving data reliably, because those are the same for every partner and they are where teams fail. That means registering each file with a checksum so a re-delivery is recognised, loading into a staging table with COPY so loading never fails on bad data, validating in stages and marking each row valid or rejected with a reason, merging valid rows in small batches with idempotent upserts so any step can be re-run, producing an error report the partner can use, and keeping an audit trail of which file produced which record.

Then, if they want more

I would deliver that as a shared library on top of Spring Batch first, because it gives restartable chunked jobs and job history, and consider a central platform service only if the number of pipelines grows enough to justify a team.

What I would leave to teams is the meaning: domain validation rules and the mapping into their model, plugged into the standard pipeline. The standard also protects the database: load windows outside peak, a separate role per pipeline with connection limits and statement timeouts, small transactions and throttling on replica lag.

For build versus buy, I would look at volume, the number of formats and partners, compliance needs and who operates it, and write the decision down so we revisit it when those numbers change.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Several teams build their own bulk import pipelines for partner files, each with...": https://scrivio-interview-library.netlify.app/databases/query-optimization/56c8eedbe4/