Abrova
☰ Docs menu · Batch
Coming soon. Abrova Sync is coming soon. This page describes how it will work; it can’t be used yet.

Batch Operations

Execute multiple Abrova Sync writes (set, update, delete, create) atomically as a single transaction. All operations succeed together or all roll back. Available on Flutter, React Native, Web, Android, iOS, Node.js, and REST API.

Last updated: 27 Oct 2026

Batch operations let you execute multiple write operations as a single atomic unit. Either every operation succeeds, or none do — perfect for maintaining data consistency when one logical update spans multiple documents (think money transfers, multi-step workflows, dependent records).

Multi-step workflows

Update records, counters, and status flags as one atomic transaction so they never drift apart.

Money transfers

Debit one account and credit another together — never one without the other.

Bulk updates

Update many related documents together so your data is never in a half-applied state.

Data migrations

Safely move data between collections with all-or-nothing guarantees.

Available operations#

A batch holds an in-memory list of writes. Add as many as you need, then call commit() to ship them as one atomic request. Four operation types are supported:

OperationPurpose
set()Create a document or replace it entirely if it exists. With the merge option it merges the fields instead (as in CRUD).
update()Apply a partial update — merge fields into an existing document.
delete()Remove a document.
create()Create a new document with an auto-generated ID.

Flutter#

dart
// Create a batch for atomic operations
final batch = AbrovaSync.batch();

// Add multiple operations to the batch
batch.set(usersCollection, 'user1', {'name': 'John', 'status': 'active'});
batch.update(ordersCollection, 'order123', {'status': 'shipped'});
batch.delete(cartCollection, 'cart456');
batch.create(logsCollection, {'action': 'order_shipped', 'timestamp': DateTime.now().toIso8601String()});

// Commit all operations atomically
await batch.commit();
// All operations succeed or fail together!

React Native#

typescript
// Create a batch for atomic operations
const batch = AbrovaSync.batch();

// Add multiple operations to the batch
batch.set(usersCollection, 'user1', { name: 'John', status: 'active' });
batch.update(ordersCollection, 'order123', { status: 'shipped' });
batch.delete(cartCollection, 'cart456');
batch.create(logsCollection, { action: 'order_shipped', timestamp: new Date().toISOString() });

// Commit all operations atomically
await batch.commit();

Web#

typescript
// Create a batch for atomic operations
const batch = abrovaSync.batch();

// Add multiple operations to the batch
batch.set(usersCollection.document('user1'), { name: 'John', status: 'active' });
batch.update(ordersCollection.document('order123'), { status: 'shipped' });
batch.delete(cartCollection.document('cart456'));
batch.create(logsCollection, { action: 'order_shipped', timestamp: new Date().toISOString() });

// Commit all operations atomically
await batch.commit();

Android#

kotlin
// Create a batch for atomic operations
val batch = AbrovaSync.getInstance().batch()

// Add multiple operations to the batch
batch.set(usersCollection, "user1", mapOf("name" to "John", "status" to "active"))
batch.update(ordersCollection, "order123", mapOf("status" to "shipped"))
batch.delete(cartCollection, "cart456")
batch.create(logsCollection, mapOf("action" to "order_shipped"))

// Commit all operations atomically
lifecycleScope.launch {
    batch.commit()
}

iOS#

swift
// Create a batch for atomic operations
let batch = AbrovaSync.shared.batch()

// Add multiple operations to the batch
batch.set(usersCollection, documentId: "user1", data: ["name": "John", "status": "active"])
batch.update(ordersCollection, documentId: "order123", data: ["status": "shipped"])
batch.delete(cartCollection, documentId: "cart456")
batch.create(logsCollection, data: ["action": "order_shipped"])

// Commit all operations atomically
try await batch.commit()

Node.js#

The Node.js SDK's batch supports set(), update() and delete() (no create()). Like every other SDK, commit() is atomic: all operations are written together, or none is when one is refused.

typescript
// Create a batch for atomic operations
const batch = abrovaSync.batch();

// Add multiple operations to the batch
batch.set(users.doc('user1'), { name: 'John', status: 'active' });
batch.update(orders.doc('order123'), { status: 'shipped' });
batch.delete(carts.doc('cart456'));

// Commit all operations atomically
await batch.commit();

REST API#

The REST API exposes batches as a single POST with an operations array. If any operation fails, the whole batch rolls back — the response tells you which one and why.

bash
# Batch Operations via REST API
# Execute multiple operations atomically in a single request

curl -X POST "https://sync.abrova.ir/batch/sdk" \
  -H "x-api-key: YOUR_PROJECT_API_KEY" \
  -H "x-server-secret: YOUR_SERVER_SECRET" \
  -H "Content-Type: application/json" \
  -d '{
    "operations": [
      {
        "type": "set",
        "databaseId": "my-app",
        "collectionId": "users",
        "documentId": "user1",
        "data": { "name": "John", "status": "active" }
      },
      {
        "type": "update",
        "databaseId": "my-app",
        "collectionId": "orders",
        "documentId": "order123",
        "data": { "status": "shipped" }
      },
      {
        "type": "delete",
        "databaseId": "my-app",
        "collectionId": "carts",
        "documentId": "cart456"
      }
    ]
  }'

# Response on success:
# { "success": true, "operationCount": 3 }
# If ANY operation fails, ALL are rolled back

When a batch is refused, commit() throws (or rejects) and nothing is saved. The error's statusCode is 403 when your security rules refused one of the operations. On Android, commit() throws an AbrovaSyncException.BatchWriteException whose cause is the server's answer, a NetworkException with that statusCode. See Platform Notes for the error types.

Batches and your security rules.

Every operation in a batch is checked by your security rules before anything is saved; if one is refused, nothing is. Rules see the database as it was before the batch, and getAfter() sees it as it will be after — so a batch can, for example, create a team and make its creator the admin in one go. In the REST body, a set operation takes "merge": true to merge.

Batch size limit.

Batch operations have a limit of 500 operations per batch. For larger operations, split them into multiple batches or use background jobs.

Was this page helpful?
Report a problem