Skip to main content
Use batch operations for efficient bulk data processing. OnDB’s store() method accepts arrays of records, and for large-scale imports you can partition data into chunks.

Basic Batch Storage

Store multiple records in a single call:
TypeScript

Large Dataset Processing

For large datasets, chunk your data into manageable batches:
TypeScript

Error Handling in Batches

Retry with Exponential Backoff

TypeScript

Distributed Bulk Operations

When processing large datasets across multiple OnDB client instances (e.g., multiple workers, microservices, or serverless functions), you need coordination for global progress tracking and deduplication.

Deduplication with Unique Indexes

Create a unique hash index on a natural key or a dedicated import_id field to prevent duplicate records when multiple workers process overlapping data:
With a unique index, duplicate records are rejected automatically. Workers can safely retry failed batches without risk of duplicates.

Multi-Worker Partitioning

Split work across multiple clients by partitioning the input dataset. Each worker handles a disjoint range:

Global Progress Tracking

Use a shared coordination collection to track progress across all workers. Each worker writes its progress, and any client can query the aggregate state:

Using Sharding for Distributed Writes

For high-volume distributed ingestion, combine sharding with multi-worker writes so each worker targets a specific shard, avoiding write contention:
See Sharding for full configuration options.

Concurrency Tuning

When running multiple workers, adjust concurrency based on your needs:

Next Steps

Sharding

Partition collections for distributed writes

Task Management

Track async operations

Transaction Tracking

Monitor transaction status

Collections & Indexes

Unique indexes for deduplication