~/docs/guides/concurrency
DOCUMENTATION
Concurrency
Multi-threaded access and parallel reads
KiteDB supports concurrent access from multiple threads, enabling parallel reads for improved throughput in multi-threaded applications.
Concurrency Model
KiteDB uses a readers-writer lock pattern:
- Multiple concurrent readers – Any number of threads can read simultaneously
- Exclusive writer – Write operations acquire exclusive access
- MVCC isolation – Transactions see consistent snapshots
typescript
Performance Notes
Read throughput typically improves with parallel readers, while write throughput is constrained by serialized commit ordering. Measure with your workload and tune batch sizes and sync mode accordingly.
Best Practices
- Batch writes – Group multiple writes into single operations to minimize exclusive lock time
- Use transactions for consistency – MVCC ensures readers see consistent snapshots even during concurrent writes
- Profile your workload – The optimal thread count depends on your read/write ratio and data access patterns
- Avoid long-held locks – Keep critical sections short; do processing outside the lock
MVCC and Transaction Semantics
KiteDB uses Multi-Version Concurrency Control (MVCC) with serialized writes:
- Multiple readers can run concurrently
- A write waits for in-flight reads, then blocks new reads while it commits
- Each committed transaction is atomic
- Write conflicts are detected at commit time
typescript
Limitations
- Single-process only – Concurrent access is within a single process; multi-process access requires external coordination
- Write serialization – All writes are serialized; high-write workloads may see contention
- Memory overhead – MVCC maintains version history, using additional memory
Next Steps
- Transactions – Learn about ACID guarantees
- Benchmarks – See detailed performance numbers
- Architecture – Understand the internal design