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 | Throughput | Use Case |
|---|---|---|
| Embedded | ~100k jobs/sec | Single process |
| TCP | Network limited | Distributed workers |
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;
all affected shard locks are held through publication, and configured SQLite
commits every node before workers are notified. 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.