# How does the Bulk API handle high-volume data migrations and asynchronous enterprise synchronization jobs?

**Topic:** Integration · **Difficulty:** Medium · **Tags:** Integration, Bulk API, Asynchronous Processing

Read it on the site: https://www.forcechallenges.com/interview-questions/how-does-the-bulk-api-handle-high-volume-data-migrations-and-asynchronous-enterprise-synchronization-jobs

## Answer

**Basics:** Standard REST/SOAP calls handle roughly 200 records each and are synchronous, which is slow and expensive for millions of rows. Bulk API is designed for loads, deletes, hard deletes and large queries. Two versions exist: **Bulk API 1.0** (you create batches yourself, XML/JSON/CSV) and **Bulk API 2.0** (simpler: upload one CSV, Salesforce splits it automatically).

**How it works (Bulk API 2.0):**
1. Create an ingest job: `POST /services/data/vXX.0/jobs/ingest` with object, operation (insert, update, upsert, delete, hardDelete) and external ID field for upsert.
2. Upload CSV data with `PUT .../jobs/ingest/{id}/batches` (about 100 MB raw per job upload, 150 MB base64, verify limits).
3. Mark the job `UploadComplete` using PATCH.
4. Salesforce processes it asynchronously and in parallel.
5. Poll the job status, then download `successfulResults`, `failedResults` and `unprocessedrecords`.
Query jobs (`/jobs/query`) export big result sets the same way.

**Advanced / deep dive:** Bulk API 1.0 gives control: batches up to 10,000 records, parallel or **serial** mode, and **PK chunking** for huge queries (chunk size default 100,000, max 250,000). Bulk 2.0 removes batch management but gives less control. Parallelism causes **record lock contention** (UNABLE_TO_LOCK_ROW) on child records of the same parent, so sort the data by parent ID or use serial mode. Triggers, flows and validation rules still run per record, so heavy automation can make jobs slow; use bypass switches carefully. The daily allocation counts batches (1.0) or total records (2.0); verify current numbers in the limits documentation. Data Loader, Dataloader.io and most ETL tools can use Bulk API underneath.

**Code / config example:**
```
POST /services/data/vXX.0/jobs/ingest
{ "object": "Contact", "operation": "upsert",
  "externalIdFieldName": "ERP_Id__c", "contentType": "CSV", "lineEnding": "LF" }
```

**Hidden gotchas & must-remember points:**
- Bulk API 2.0 accepts CSV only for ingest.
- Partial success is the norm; always process the failed results file.
- Lock contention is the most common failure; order by parent.
- Results are retained only for a limited time (about 7 days), so download them.
- It is not for real-time use; latency is minutes.
- Bulk API is separate from Apex Batch; do not confuse them.

**Best practice:** Use Bulk API 2.0 for migrations and nightly syncs, use upsert with an External ID, test in a sandbox with realistic automation enabled, and always capture the failed-records file.

---
Source: ForceChallenges · last updated 2026-11-02
