REST API Bulk Operations
Some tasks involve many records at once. An admin imports 500 products, a mobile app syncs 80 notes, and a system deletes 200 expired sessions. Sending one request per record floods the network and slows everything down. Bulk operations let one request carry many changes.
The Moving Boxes Picture
Moving to a new home with one trip per item would take weeks. Packing items into boxes and loading a truck finishes the job in a day. Bulk endpoints act like the truck. They carry many items in a single trip.
One by One vs Bulk
One by one: Client ──→ Server (100 requests, 100 responses)
Client ──→ Server
Client ──→ Server ...
Bulk: Client ══ [ 100 items ] ══→ Server (1 request, 1 response)
Designing Bulk Endpoints
Two common patterns exist. The first sends an array to the collection URL. The second uses a dedicated bulk path.
POST /products
[
{ "name": "Pen", "price": 5 },
{ "name": "Notebook", "price": 40 }
]
POST /products/bulk
{
"items": [
{ "name": "Pen", "price": 5 },
{ "name": "Notebook", "price": 40 }
]
}
A dedicated path keeps single-item and bulk behavior separate, which simplifies validation and documentation.
All or Nothing vs Partial Success
Every bulk design must answer one question. What happens when one item fails?
All or Nothing
The server wraps the batch in a transaction. A single failure cancels every change. This style suits financial records and data that must stay consistent.
Partial Success
The server processes each item on its own and reports a result per item. This style suits imports and syncs where most items usually pass. The status code 207 Multi-Status signals a mixed result.
HTTP/1.1 207 Multi-Status
{
"results": [
{ "index": 0, "status": 201, "id": 801 },
{ "index": 1, "status": 422, "error": "price must be positive" },
{ "index": 2, "status": 201, "id": 802 }
]
}
Each result carries the item position, so the client knows which entries to fix and resend.
Setting Limits
Unlimited batches can overload a server. Set a maximum item count, such as 100 or 1000, and a maximum body size. Return 413 Content Too Large when a request exceeds the limit, and state the limit in the documentation.
Bulk Delete and Bulk Update
Bulk deletes accept a list of ids.
POST /sessions/bulk-delete
{ "ids": [11, 12, 15, 19] }
Bulk updates pair each id with its changes.
PATCH /products/bulk
{
"items": [
{ "id": 3, "price": 6 },
{ "id": 4, "price": 45 }
]
}
Handling Very Large Jobs
Thousands of items take too long for a single response. Accept the job, return 202 Accepted with a status URL, and process the batch in the background. The client checks the status URL until the job finishes.
Safe Retries
Bulk requests fail halfway more often than single requests do. Support an Idempotency-Key header so a retry does not create duplicates. Per-item client references also help the server detect repeats.
Common Mistakes
Hiding Failures
Returning 200 for a batch where half the items failed misleads clients. Report each item result clearly.
No Ordering Rules
State whether the server processes items in order. Clients depend on order when later items refer to earlier ones.
Skipping Limits
A single oversized request can stall other users. Enforce limits from the first release.
