Distributed Workflow Orchestration & Job Queue Platform (BullMQ + Redis + PostgreSQL)
JobFlow is a high-performance distributed task processing and workflow orchestration platform. It is designed to coordinate complex multi-step jobs represented as Directed Acyclic Graphs (DAGs) with sequential, parallel, and conditional execution paths, complete with persistent state logs, retry backoff policies, distributed worker scaling, and real-time observability.
JobFlow has evolved into a production-grade distributed orchestration platform:
- Workflow Engine & Orchestrator (Phase 7): Executes DAG-based workflows, detects cycles, processes step dependencies, evaluates branch conditions (e.g.
steps.<stepId>.status === 'COMPLETED'), and handles cascade cancellation of downstream execution paths. Includes templates for Lead Nurturing, Image Optimization, and Notification campaigns. - Real-Time Gateway (Phase 8): Socket.IO server utilizing JWT authentication. Separates connections into personal user rooms (
room:user:<id>), detailed workflow timeline rooms (room:workflow:<id>), and system operator rooms (room:admins). Automatically replays cached events upon reconnection and throttles progress updates to 200ms. - Persistent Notifications (Phase 8): Database-backed system alerts categorizing failures, retries, and completions. Exposes list, mark read, and delete endpoints.
- System Audit Logging (Phase 8): Tracks administrative actions (e.g. creations, retries, cancellations, logins, worker check-ins) across users and resources. Exposes operator queries.
- Chronological Timelines (Phase 8): Aggregates workflow history logs into sequence timelines.
- Prometheus Metrics (Phase 8): Exposes a standard scrapable
/metricsendpoint with queue size gauges, total completed/failed counters, and worker utilization gauges. - Distributed Tracing (Phase 8): Injects and extracts
X-Correlation-IDheaders usingAsyncLocalStorageto trace requests across the logging layer, queue payloads, and worker processing execution contexts.
- Runtime: Node.js (v20+)
- Framework: Express.js (v4)
- Language: TypeScript
- Database: PostgreSQL (v15+)
- ORM: Prisma ORM (v5)
- Queue Engine: BullMQ & Redis
- WebSockets: Socket.IO
- Metrics: prom-client (Prometheus Exporter)
- Logger: Winston (Prepend Correlation IDs)
- API Validation: Zod
- Authentication: JWT & Bcrypt
- Testing: Native Node.js Test Runner & Supertest
jobflow/
βββ backend/
β βββ prisma/
β β βββ schema.prisma # Database definitions (User, Job, Workflow, Notifications, AuditLog)
β β βββ migrations/ # SQL migration files
β βββ src/
β β βββ config/ # Environment configurations (Redis, environment variables)
β β βββ common/ # Shared operational layers
β β β βββ errors/ # Standard HTTP client/server errors
β β β βββ logger/ # Winston logger configuration
β β β βββ middleware/ # Express middlewares (auth, validation, tracing)
β β β βββ tracing/ # AsyncLocalStorage distributed trace context
β β βββ events/ # In-process type-safe Event Bus
β β βββ socket/ # WebSocket (Socket.IO) server & gateway
β β βββ queues/ # BullMQ queue definitions & handlers
β β βββ workers/ # Base worker process & lifecycle managers
β β βββ modules/ # Domain-driven features
β β β βββ auth/ # JWT Authentication & authorization
β β β βββ jobs/ # CRUD Job management & execution services
β β β βββ workflow/ # DAG engine, dependency resolver, scheduler & templates
β β β βββ monitoring/ # Metrics, audit logs, timelines, & Prometheus services
β β βββ app.ts # Configured Express application instance
β β βββ server.ts # HTTP listener, Socket.IO & Graceful Shutdown script
β β βββ worker.ts # Independent worker background process entrypoint
β βββ package.json # Build scripts & dependencies manager
β βββ tsconfig.json # TypeScript compiler configurations
β βββ README.md # Backend instructions
βββ docs/ # Architecture diagrams & guides (observability.md, workflow.md)
βββ docker-compose.yml # Dev Redis & PostgreSQL containers setup
βββ README.md # Global documentation file (This file)
Make sure you have Node.js, Docker Desktop, and Git installed.
-
Navigate to the repository workspace:
cd JOBFLOW -
Go to the
backendfolder:cd backend -
Install dependencies (installs development socket client, Prometheus tools, BullMQ, and core libraries):
npm install
-
Spin up the localized PostgreSQL and Redis containers:
docker compose up -d
-
Push the database schema configurations and generate Prisma clients:
npx prisma db push
-
Seed default users and templates:
npx prisma db seed
Starts the Express API Web Server with live-reloads:
npm run devStarts the Background Worker Consumer process with live-reloads:
npm run worker:devCompile the TypeScript files to JS:
npm run buildRun the compiled web server:
npm run startRun the compiled worker process:
npm run workerJobFlow includes a comprehensive integration test suite verifying authentication, job queues, workers retry handling, DAG workflow scheduling, Socket.IO gateway rooms, trace propagation, notifications, audit logs, and metrics scraping:
npm run testPOST /api/v1/auth/registerβ Create a user.POST /api/v1/auth/loginβ Returns access & refresh token.POST /api/v1/auth/refreshβ Rotation of session keys.GET /api/v1/auth/meβ Fetches current authenticated payload.
POST /api/v1/jobsβ Enqueue a new stand-alone job.GET /api/v1/jobsβ Lists user-enqueued jobs.GET /api/v1/jobs/:idβ Retrives details and runtime progress percentage.POST /api/v1/jobs/:id/cancelβ Cancels a running/queued job.
POST /api/v1/workflowsβ Instantiates a new workflow (sequential or parallel execution graph).GET /api/v1/workflowsβ Lists user workflows.GET /api/v1/workflows/:idβ Retrieves current workflow details.POST /api/v1/workflows/:id/cancelβ Stops execution and cancels downstream paths.POST /api/v1/workflows/:id/retryβ Resumes execution of failed steps.GET /api/v1/workflows/templatesβ Lists predefined DAG campaigns.GET /api/v1/workflows/metricsβ Aggregate workflow performance (durations, success rates).
GET /api/v1/notificationsβ Paginated user alerts.PATCH /api/v1/notifications/:id/readβ Marks notification as read.DELETE /api/v1/notifications/:idβ Removes notification.
GET /metricsβ Exposes Prometheus format metrics scraper registry.GET /api/v1/monitoring/dashboardβ General summary statistics (restricted toADMIN).GET /api/v1/monitoring/queuesβ Retrieves active/waiting counts in BullMQ (restricted toADMIN).GET /api/v1/monitoring/workflowsβ Overall platform execution metrics (restricted toADMIN).GET /api/v1/monitoring/workersβ Worker check-in status, uptime, CPU and memory usage (restricted toADMIN).GET /api/v1/monitoring/logsβ Query security and operations audit logs (restricted toADMIN).GET /api/v1/monitoring/workflows/:id/timelineβ Sequential execution updates for steps.