Skip to main content

Shard-aware high-performance bulk insert using serde_avro_fast for encoding.

BulkInserter routes records to the correct worker based on shard key computation, enabling true multi-head ingest where each record is sent directly to the worker that owns its shard.

How Shard-Aware Routing Works

  1. On initialization, fetch the routing table via admin_show_shards
  2. Fetch the table schema via show_table to identify shard key columns
  3. Build a RecordKeyBuilder to compute routing keys
  4. For each record, compute its shard key hash using all shard key columns
  5. Use the routing table to determine which worker owns that shard
  6. Route the record directly to that worker

Performance

  • Shard-aware routing eliminates server-side record redistribution
  • Each worker receives only records that belong to its shards
  • Faster Avro encoding with serde_avro_fast (~6-7x faster than apache-avro)
  • Parallel encoding with rayon for maximum throughput

Insert Methods

The BulkInserter provides four insertion methods:

MethodUse CaseQueue Throughput
insertSingle record streaming~3-7M rec/s
insert_with_backpressureMemory-bounded streaming~3-7M rec/s
insert_batchBulk loading~20-30M rec/s
insert_batch_arcPre-wrapped records~30-35M rec/s

The batch methods use parallel shard key computation and reduce lock contention by grouping records before acquiring locks. This provides up to 8x faster client-side queue throughput for large batches.

JSON Records

BulkInserter::new_json and BulkInserter::with_json_options make a BulkInserter<String> taking JSON objects as text: each record goes to the rank of a random shard, and each batch is sent as one JSON array to /insert/records/json.

Further Features

Backpressure Control

Use insert_with_backpressure() for memory-bounded operation:

Timed Flush

Configure automatic periodic flush:

Error Queue

Non-blocking async error collection:

Batch Callbacks

Real-time monitoring via BatchInsertionListener:

Example

Re-exports

pub use crate::bulk_inserter_common::ShardKeyExtractor;
pub use crate::bulk_inserter_common::ShardKeyValue;
pub use crate::bulk_inserter_common::ShardKeyValues;

Modules

Constants for InsertRecordsRequest options.

Structs

Metrics for monitoring backpressure behavior.
Result of a batch insertion attempt. This is passed to the batch listener callback after each batch completes.
Shard-aware high-performance bulk inserter.
Options for configuring the BulkInserter.
Options for controlling automatic flush behavior.
Simple function-based listener wrapper
An error that occurred during batch insertion. These are collected in the error queue for async error handling.
Records the inserter did not queue, and why, for the caller to retry or report.

Traits

Callback trait for batch insertion events. Implement this trait to receive notifications when batches complete.