Skip to content

Batch

Multiple operations in a single request

Extension URN: urn:mesh:ext:batch


The batch extension enables multiple operations in a single request. Reduces round trips and enables atomic transactions across operations.


Batch operations SHOULD be used for:

  • Bulk create/update/delete operations
  • Operations requiring atomic consistency
  • Reducing network round trips
  • Related operations that should succeed or fail together

Batch operations SHOULD NOT be used for:

  • Unrelated operations
  • Operations with complex interdependencies
  • Very large batches (prefer streaming)

FieldTypeRequiredDescription
modestringYesatomic or independent
operationsarrayYesList of operations to execute
stop_on_errorbooleanNoStop processing on first error (independent mode only)
FieldTypeRequiredDescription
idstringYesUnique identifier within batch
functionstringYesFunction to call
versionstringYesFunction version
argumentsobjectYesFunction arguments

FieldTypeDescription
modestringExecution mode used
resultsarrayResults for each operation
summaryobjectAggregate statistics
FieldTypeDescription
idstringOperation ID from request
statusstringsuccess, error, or skipped
resultanyOperation result (if success)
errorobjectError details (if error)
FieldTypeDescription
totalnumberTotal operations
succeedednumberSuccessful operations
failednumberFailed operations
skippednumberSkipped operations

When mode: "atomic":

  1. Server MUST execute all operations in a transaction
  2. If ANY operation fails, ALL operations MUST be rolled back
  3. Server MUST return either all successes or all failures
  4. Operations MAY be executed in any order

When mode: "independent":

  1. Server executes operations independently
  2. Failed operations do NOT affect others
  3. If stop_on_error: true, remaining operations are skipped after first error
  4. Server SHOULD execute operations in order

{
"protocol": { "name": "mesh", "version": "0.1.0" },
"id": "req_batch",
"call": {
"function": "mesh.batch",
"version": "1",
"arguments": {}
},
"extensions": [
{
"urn": "urn:mesh:ext:batch",
"options": {
"mode": "atomic",
"operations": [
{
"id": "op1",
"function": "accounts.debit",
"version": "1",
"arguments": { "account_id": "A", "amount": 100 }
},
{
"id": "op2",
"function": "accounts.credit",
"version": "1",
"arguments": { "account_id": "B", "amount": 100 }
}
]
}
}
]
}
{
"protocol": { "name": "mesh", "version": "0.1.0" },
"id": "req_batch",
"result": null,
"extensions": [
{
"urn": "urn:mesh:ext:batch",
"data": {
"mode": "atomic",
"results": [
{
"id": "op1",
"status": "success",
"result": { "new_balance": 400 }
},
{
"id": "op2",
"status": "success",
"result": { "new_balance": 600 }
}
],
"summary": {
"total": 2,
"succeeded": 2,
"failed": 0,
"skipped": 0
}
}
}
]
}

When one operation fails, all are rolled back:

{
"protocol": { "name": "mesh", "version": "0.1.0" },
"id": "req_batch",
"result": null,
"errors": [{
"code": "BATCH_FAILED",
"message": "Atomic batch failed: insufficient funds",
"retryable": false
}],
"extensions": [
{
"urn": "urn:mesh:ext:batch",
"data": {
"mode": "atomic",
"results": [
{
"id": "op1",
"status": "error",
"errors": [{
"code": "INSUFFICIENT_FUNDS",
"message": "Account A has insufficient funds"
}]
},
{
"id": "op2",
"status": "skipped"
}
],
"summary": {
"total": 2,
"succeeded": 0,
"failed": 1,
"skipped": 1
}
}
}
]
}
{
"protocol": { "name": "mesh", "version": "0.1.0" },
"id": "req_batch_ind",
"call": {
"function": "mesh.batch",
"version": "1",
"arguments": {}
},
"extensions": [
{
"urn": "urn:mesh:ext:batch",
"options": {
"mode": "independent",
"stop_on_error": false,
"operations": [
{
"id": "create1",
"function": "users.create",
"version": "1",
"arguments": { "email": "alice@example.com", "name": "Alice" }
},
{
"id": "create2",
"function": "users.create",
"version": "1",
"arguments": { "email": "bob@example.com", "name": "Bob" }
},
{
"id": "create3",
"function": "users.create",
"version": "1",
"arguments": { "email": "invalid-email", "name": "Charlie" }
}
]
}
}
]
}
{
"protocol": { "name": "mesh", "version": "0.1.0" },
"id": "req_batch_ind",
"result": null,
"extensions": [
{
"urn": "urn:mesh:ext:batch",
"data": {
"mode": "independent",
"results": [
{
"id": "create1",
"status": "success",
"result": { "user_id": 101, "email": "alice@example.com" }
},
{
"id": "create2",
"status": "success",
"result": { "user_id": 102, "email": "bob@example.com" }
},
{
"id": "create3",
"status": "error",
"errors": [{
"code": "INVALID_ARGUMENTS",
"message": "Invalid email format"
}]
}
],
"summary": {
"total": 3,
"succeeded": 2,
"failed": 1,
"skipped": 0
}
}
}
]
}

Servers SHOULD enforce batch limits:

LimitRecommended
Max operations100
Max payload size1 MB
Timeout60 seconds

Servers MUST return BATCH_TOO_LARGE error when limits exceeded.


CodeDescription
BATCH_FAILEDAtomic batch failed (one or more operations failed)
BATCH_TOO_LARGEToo many operations or payload too large
BATCH_TIMEOUTBatch execution exceeded timeout