Robust AI workflow on Node.js using BullMQ and PostgreSQL
The architecture of robust AIworkflow requires a strict separation of responsibilities: LLM should not manage state or business logic. Building a production-ready system on Node.js includes receiving webhooks with authentication, securely storing the original data in PostgreSQL, asynchronous processing through queues BullMQ and Redis, and only then calling OpenAI for limited text interpretation. Validation of the neural network response is performed using Zod, and the database stores the final result, ensuring idempotency and protection from duplicates.

An example implementation includes an Express API that accepts work items and instantly returns an HTTP 202 Accepted status without waiting for a response from the AI. In the background, worker BullMQ takes the task from Redis, extracts the complete data from PostgreSQL and generates a prompt for OpenAI. The model returns JSON with category and priority, which is strictly checked by the Zod schema. If the task is related to security or access to accounts, the system forces the flag to require manual verification.
Source: DEV Community