Design an API batch endpoint: manage results and failures across requests
A batch endpoint sends several subrequests in one outer HTTP request body. It can reduce network round trips, but the batch is not automatically one atomic operation and all items do not necessarily succeed together. The API must define per-request results, execution order, transaction boundaries, size limits, and error handling as separate parts of its contract.
A batch endpoint sends several subrequests in one outer HTTP request body. It can reduce network round trips, but the batch is not automatically one atomic operation and all items do not necessarily succeed together. The API must define per-request results, execution order, transaction boundaries, size limits, and error handling as separate parts of its contract.
Purpose and basic contract
Batching can group requests into one HTTP round trip and reduce network latency. OData uses POST /$batch with multipart/mixed or, depending on the implementation, JSON. Microsoft Graph JSON batching gives each subrequest properties such as id, method, and url. These are examples of different contracts; batch formats vary by API.
Each item should include a unique operation ID, HTTP method, permitted relative URL, and any required headers and body. The response should use the same IDs to associate each subresponse with its status and body. Microsoft Graph documentation says response order can differ from request order, so correlate by ID rather than array position.
Define atomicity and order separately
Sending a batch in one request does not itself guarantee a transaction. An OData change set is defined as a group in which all operations are applied or none are, but that does not make independent reads or other groups in the batch atomic. Microsoft Graph JSON batches can express dependencies with dependsOn; this controls order and failure of dependent steps, not a general database transaction.
The API contract should state:
Whether items run in parallel or sequentially by default, and how required ordering is expressed.
Which operations form an atomic group and whether prior changes roll back if one fails.
What status dependent operations receive when a prerequisite fails.
How callers interpret the outer HTTP response and individual responses when independent items partly succeed.
If all-or-nothing behavior is required, do not assume that placing operations in a batch provides it. Expose an explicit transaction group supported by the server.
Per-item status and safe retries
Subrequests can fail even when the outer batch HTTP response succeeds. Microsoft Graph explains that when the batch body is parseable, the outer response can be 200 while individual operations have their own status values. Clients should collect results by item ID and determine success per operation.
Design retries per item. Resending the entire batch after a temporary throttling response or network interruption can repeat an operation that already succeeded, such as creating a record or charging a payment. Document each operation's idempotency, whether it supports an idempotency key, whether only failed items can be retried, and how callers can check whether an operation was already applied. HTTP method semantics and side effects still matter inside a batch.
Apply limits, permissions, and quotas
Batching can increase the number of operations and body size handled in one request. Set limits for item count, total body size, nesting, execution time, and dependency depth. Microsoft Graph JSON batching currently documents a limit of 20 requests, but that is a Graph-specific limit, not a general rule for batch APIs.
Check the authenticated user's permissions and limits for each subrequest. A bundled request must not bypass ordinary endpoint access control, input validation, rate limits, quotas, or audit logging. Applying both batch-level and per-operation limits helps prevent a batch from becoming a way to evade limits.
Implementation and verification procedure
Define the batch format and allowed methods, paths, and body types.
Require unique item IDs and process every item through the same validation and authorization path as a normal request.
Implement parallel or sequential execution, dependencies, atomic groups, and partial-failure behavior explicitly.
Limit item count, body size, execution time, and nesting or dependency depth; apply existing limit policies.
Check responses for full success, partial failure, dependency failure, duplicate IDs, malformed bodies, retries, and large batches.
During verification, inspect every subrequest ID, status, header, and body, not only the outer batch status. If transactions are documented, verify in an integration environment that data is actually rolled back after a mid-group failure. These are verification steps, not a claim that a particular batch implementation was run.
Sources
[OData 3.0 Protocol: Batch Request](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-odata/dd99aa5c-d81e-4eac-9e07-039491356bf6)
[ASP.NET Core OData 8: Batch requests](https://learn.microsoft.com/en-us/odata/webapi-8/fundamentals/overview)
[Microsoft Graph: Combine multiple HTTP requests using JSON batching](https://learn.microsoft.com/en-us/graph/json-batching)
[Microsoft Graph SDKs: Batch requests](https://learn.microsoft.com/en-us/graph/sdks/batch-requests)