- Docs
- Architecture
- Application Layer
Use cases in the application layer.
The application layer orchestrates all queue operations, coordinating between the client layer and domain layer: PUSH, PULL and ACK flows, stall detection, dependency resolution, and background tasks.
The server selects one application manager at startup. QueueManager owns the
synchronous memory/SQLite path shown in the diagrams below;
PostgresQueueManager exposes the same handler-facing operations but commits
state through database transactions and refreshes a bounded compatibility
projection. See Storage backends for the multi-broker path.
Module Structure
Section titled “Module Structure”src/application/├── queueManager.ts # Central orchestrator├── postgresQueueManager.ts # PostgreSQL manager facade├── postgres-queue-manager/ # Transactional operations and local projection├── operations/ # PUSH, PULL, ACK, Query├── backgroundTasks.ts # Task orchestration├── cleanupTasks.ts # Memory cleanup, orphan removal├── clientTracking.ts # Client connection tracking├── contextFactory.ts # Context creation helpers├── dependencyProcessor.ts # Dependency resolution├── dlqManager.ts # Dead letter queue├── eventsManager.ts # Event pub/sub├── jobLogsManager.ts # Job logs management├── latencyTracker.ts # Operation latency percentiles├── lockManager.ts # Lock management├── lockOperations.ts # Lock acquire/release ops├── metricsExporter.ts # Prometheus metrics export├── monitoringChecks.ts # Periodic health checks├── stallDetection.ts # Stall detection├── statsManager.ts # Queue statistics├── taskErrorTracking.ts # Background task circuit breaker├── throughputTracker.ts # Push/pull/ack rate tracking├── types.ts # Shared type definitions├── webhookManager.ts # Webhook notifications└── workerManager.ts # Worker trackingPostgresQueueManager replaces the base delivery and lifecycle operations at
the same handler boundary. Admissions and terminal transitions commit job
state, ownership, results, and durable events together; pulls claim ordered
rows with FOR UPDATE SKIP LOCKED; ACK/FAIL validates database-clock leases and
broker-session tokens. A bounded local projection serves compatibility reads
and is repaired from the durable outbox plus polling. The complete transaction,
lease, and replay model is documented in the repository reference
docs/features/postgres-multibroker.md, the architecture overview,
and the user-facing storage guide.
QueueManager Orchestration
Section titled “QueueManager Orchestration”PUSH Operation Flow
Section titled “PUSH Operation Flow”PULL Operation Flow
Section titled “PULL Operation Flow”The authoritative priority heap and secondary ungrouped, delayed and per-group indexes change under the same synchronous shard lock. A blocked group requires no heap scan or temporary reinsertion.
ACK Operation Flow
Section titled “ACK Operation Flow”Background Tasks
Section titled “Background Tasks”Processing timeouts use one next-deadline timer keyed by each active job's startedAt + timeout. Far-future timers are safely chunked at the runtime ceiling; failed timeout transitions are logged and retried.
Stall Detection (Two-Phase)
Section titled “Stall Detection (Two-Phase)”Why two-phase? It prevents false positives from transient delays, like a GC pause or a network hiccup.
Dependency Resolution
Section titled “Dependency Resolution”Cleanup Tasks
Section titled “Cleanup Tasks”Event Broadcasting
Section titled “Event Broadcasting”Event-based waiting, no polling: waitForJobCompletion(jobId, timeout) resolves when the 'completed' event for jobId arrives.