- Docs
- Architecture
- Client SDK
Thin client, smart server.
The client layer provides the interface for applications to interact with bunqueue. It supports both embedded (in-process) and TCP (server) modes.
Module Structure
Section titled “Module Structure”src/client/├── queue/ # Job submission (Queue class)├── worker/ # Job processing (Worker class)├── tcp/ # Network communication├── flow.ts # Job dependencies (FlowProducer)└── queueGroup.ts # Namespace isolationDual-Mode Architecture
Section titled “Dual-Mode Architecture”| Mode | Published workload median | Use case |
|---|---|---|
| Embedded + SQLite | 186,384 jobs/s, public on-disk addBulk | Single process |
| TCP + SQLite | 158,779 jobs/s, PUSHB | Distributed clients, one broker |
| TCP + PostgreSQL | See the multi-broker benchmark matrix | Distributed clients and brokers |
These are workload-specific ingestion medians, not a universal per-job rate. See Engineering Benchmarks for distributions and lifecycle throughput.
Job Submission Flow
Section titled “Job Submission Flow”Auto-batching (TCP mode, on by default): concurrent add() calls are transparently coalesced into a single PUSHB round-trip (defaults: maxSize 50, maxDelayMs 5). Sequential awaits send immediately with no penalty; durable jobs bypass the batcher and go out as individual PUSH.
Worker Processing Flow
Section titled “Worker Processing Flow”After each batch the worker returns to the poll loop.
Connection Pool Architecture
Section titled “Connection Pool Architecture”Key Features:
- 4 connections per pool (default)
- Load-aware client selection
- Automatic reconnection with exponential backoff
- Shared pools across Queue/Worker instances
Heartbeat & Stall Detection
Section titled “Heartbeat & Stall Detection”ACK Batching Flow
Section titled “ACK Batching Flow”Benefits:
- Reduces network round-trips
- Batches lock verification
- Handles retry on failure
FlowProducer (Dependencies)
Section titled “FlowProducer (Dependencies)”The Bun client plans the complete graph and commits it through one PUSHF
operation in both embedded and TCP modes. Validation occurs before mutation;
in memory/SQLite mode all affected shard locks are held through publication,
and configured SQLite commits every node before workers are notified. A
PostgreSQL server instead commits the complete graph and ownership edges in one
database transaction, then refreshes its projection; it does not use the base
manager’s shard locks. All six current external SDKs use the same atomic
command. PUSH plus UpdateParent remains compatible for previously published
clients; a predeclared late edge is a child-only durable back-patch and never
rewrites an active or terminal parent.