Updated 24 October 2026
Bulk imports and exports
Designing features that move large amounts of data in and out of a system: CSV and file uploads processed as background jobs, validation and partial failures, idempotent resumable imports, throttling to protect production, streaming exports, presigned download links, scheduled and incremental exports, and APIs for bulk operations.
Try it yourself, in a playground:Batching
Sooner or later every product needs bulk data movement: a merchant uploads 200,000 products from a spreadsheet, an enterprise customer exports all their records for an audit, a host syncs listings from another platform, a finance team downloads a year of transactions. Done naively in a request handler, these time out, overload the database and leave half-imported data behind. Interviewers occasionally ask about them directly, and they are a good example of asynchronous job design.
Imports as background jobs
- The client uploads the file directly to object storage with a presigned URL. See media uploads and processing.
- The API creates an import job record (
pending) and enqueues it; the response is202 Acceptedwith a job id. See background jobs. - A worker streams the file (never loading it all into memory), parses and validates rows, and writes them in batches.
- Progress (rows processed, succeeded, failed) is stored on the job and shown to the user; completion triggers a notification.
Validation and partial failure
- Validate early: check headers, encoding and a sample of rows before starting, and fail fast with a clear message if the format is wrong.
- Per-row errors: collect invalid rows (with line numbers and reasons) into an error report the user can download and fix, rather than failing the whole import.
- Decide the semantics explicitly: all-or-nothing (stage everything, then commit in one switch) or best effort (import valid rows, report the rest). All-or-nothing suits financial data; best effort suits catalogues.
- For all-or-nothing at scale, write into a staging table or a new version, validate, then atomically publish. See data quality and data contracts.
Idempotent and resumable
Workers crash and jobs retry:
- Process in chunks with a checkpoint (byte offset or row number) saved after each committed batch, so a retry resumes rather than restarting.
- Make writes idempotent: upsert by a natural key (SKU, external id) or by (import id, row number), so reprocessing a chunk does not duplicate rows. See idempotency keys in practice.
- Uploading the same file twice should be detected (content hash) or harmless.
Protecting production
A large import competes with live traffic:
- Throttle write rates per tenant; use a separate, lower-priority worker pool. See multi-tenancy.
- Batch inserts and use bulk APIs; disable or defer expensive per-row side effects (emails, webhooks) or coalesce them.
- Update secondary systems (search index, caches) asynchronously through the normal change stream rather than inline. See change data capture.
- Watch replica lag and database load, pausing when they rise. See online schema migrations for the same backfill techniques.
Exports
- Run as a background job; stream query results in pages (keyset pagination) into a file in object storage, compressing as you go. See pagination.
- Read from a replica or snapshot to avoid loading the primary, and to get a consistent point-in-time view.
- Deliver with a short-lived presigned download link, sent by email or shown in the app; expire files after a few days.
- Formats: CSV for spreadsheets, JSON Lines for programmatic use, Parquet for analytics. See data lakes and lakehouses.
- Apply permissions at export time; exports are a common data leak path, so audit them. See audit logs.
Incremental and scheduled
Repeated full exports waste resources. Offer:
- Incremental exports of changes since the last export, using updated-at cursors or a change feed.
- Scheduled deliveries to the customer's storage bucket.
- Streaming integrations (webhooks or event streams) for near real-time sync. See webhooks.
Bulk APIs
For programmatic clients, provide bulk endpoints that accept many records per call (with per-item results) and asynchronous batch endpoints for very large operations, with limits on batch size and rate. See API design.
Large data transfers
For terabytes (onboarding an enterprise, migrating platforms), use multipart uploads, parallel workers, checksums per chunk, and possibly direct transfers between cloud storage buckets. Plan a verification step comparing counts and checksums. See distributed file systems.
In the interview
"Hosts upload a CSV via a presigned URL; an import job streams and validates it, upserts listings by external id in batches of 1,000 with checkpoints, throttled per host on a low-priority worker pool; invalid rows go to a downloadable error report; the search index updates through CDC. Exports stream from a replica into a compressed file with an expiring download link." See Design Airbnb.
Checklist
- Direct-to-storage upload; job record; 202 with progress tracking.
- Early format validation, per-row errors, explicit all-or-nothing or best-effort semantics.
- Chunked, checkpointed, idempotent processing.
- Throttling, separate worker pools, asynchronous side effects.
- Streaming exports from replicas to object storage with presigned links.
- Permissions and auditing on exports; incremental options.
Questions people ask
What are bulk imports and exports?
Bulk imports and exports are features that move large amounts of data in or out of a system, such as a merchant uploading 200,000 products from a spreadsheet or an enterprise customer exporting all their records for an audit. Done naively in a request handler, they time out, overload the database and leave half-imported data behind. They are built as asynchronous background jobs that stream files, write in batches and report progress.
How do you design a large CSV import?
Treat the import as a background job, not work in the request handler. The client uploads the file directly to object storage with a presigned URL, the API creates an import job record and returns 202 Accepted with a job id, and a worker streams the file without loading it all into memory, validates rows and writes them in batches. Progress (rows processed, succeeded and failed) is stored on the job and shown to the user, and completion triggers a notification.
How should a bulk import handle invalid rows?
Validate early and collect per-row errors instead of failing the whole import. Check headers, encoding and a sample of rows before starting, fail fast with a clear message if the format is wrong, and put invalid rows with line numbers and reasons into an error report the user can download and fix. Choose the semantics explicitly: all-or-nothing (stage everything, then commit in one switch) suits financial data, while best effort (import valid rows, report the rest) suits catalogues.
How do you make an import idempotent and resumable?
Process the file in chunks and save a checkpoint (byte offset or row number) after each committed batch, so a retry after a worker crash resumes rather than restarting. Make writes idempotent by upserting on a natural key such as a SKU or external id, or on (import id, row number), so reprocessing a chunk does not duplicate rows. Uploading the same file twice should be detected with a content hash or be harmless.
How do you stop a bulk import from overloading production?
Throttle write rates per tenant and run imports on a separate, lower-priority worker pool so they do not starve live traffic. Batch inserts, use bulk APIs, and defer or coalesce expensive per-row side effects such as emails and webhooks. Update secondary systems like the search index and caches asynchronously through the normal change stream, and watch replica lag and database load, pausing the import when they rise.
How do you export a large dataset for a customer?
Run the export as a background job that streams query results in pages, using keyset pagination, into a compressed file in object storage. Read from a replica or snapshot to avoid loading the primary and to get a consistent point-in-time view, then deliver the file through a short-lived presigned download link and expire it after a few days. Apply permissions at export time and audit exports, because they are a common data leak path.