Build a dependable Node.js AI workflow that accepts authenticated webhooks, stores work safely in PostgreSQL, processes jobs with BullMQ and Redis, calls OpenAI asynchronously, and returns a validated result.
What You Will Build
This tutorial builds a small, production-minded work-intake service. Another system sends a work item to POST /webhooks/work-items. The API validates the payload, stores it in PostgreSQL, adds a BullMQ job, and returns 202 Accepted without waiting for an AI response.
A separate worker receives the job from Redis, loads the canonical record from PostgreSQL, asks OpenAI to classify the item, validates the returned JSON with Zod, and saves the outcome. The API exposes GET /work-items/:id for polling and GET /ready for dependency checks.
This separation is important. An LLM can assist with bounded interpretation such as classification and summarisation, but it should not become the system of record or the policy engine. PostgreSQL owns business state. Redis and BullMQ coordinate background execution. Application code enforces deterministic handling for security-sensitive categories.






