Context
The Midaz ledger system processes high volumes of transactions that require metadata storage in MongoDB. Currently, metadata operations are performed individually for each entity, which becomes a bottleneck during batch transaction processing.
Problem/Motivation
When processing multiple transactions simultaneously, the system performs individual metadata storage operations for each transaction. This creates:
- Excessive database round-trips: Each operation requires a separate network call (100 transactions = 100 round-trips)
- Connection pool pressure: High concurrency exhausts available connections
- Retry complexity: Individual operations lack atomic batch guarantees, requiring complex application-level deduplication
- Scalability limits: Performance degrades linearly as transaction volume increases
Current Behavior
- Metadata for each entity is inserted/updated via individual
Create() and Update() calls
- No built-in idempotency protection for retries (risk of duplicate records)
- No bulk operation support in the MongoDB metadata repository interface
Goal
Implement CreateBulk() and UpdateBulk() methods for MongoDB metadata repositories that:
- Batch operations: Process up to 1000 documents per BulkWrite call
- Idempotent inserts: Use
$setOnInsert with upsert to prevent duplicates on retry
- Deadlock prevention: Sort documents by EntityID before processing
- Result tracking: Return detailed counts (attempted, inserted, matched, modified)
- Cancellation support: Respect context cancellation between chunks
- Multi-tenant aware: Automatically resolve tenant database from context
- Observable: Include OpenTelemetry tracing spans for all operations
Success Metrics
Context
The Midaz ledger system processes high volumes of transactions that require metadata storage in MongoDB. Currently, metadata operations are performed individually for each entity, which becomes a bottleneck during batch transaction processing.
Problem/Motivation
When processing multiple transactions simultaneously, the system performs individual metadata storage operations for each transaction. This creates:
Current Behavior
Create()andUpdate()callsGoal
Implement
CreateBulk()andUpdateBulk()methods for MongoDB metadata repositories that:$setOnInsertwith upsert to prevent duplicates on retrySuccess Metrics
CreateBulk()method available in onboarding and transaction metadata repositoriesUpdateBulk()method available in onboarding and transaction metadata repositories