NextFlow

A drag-and-drop visual workflow builder for chaining Large Language Models and processing media files into reliable, parallel execution graphs.

Workflow Engine · 2024 · Full-Stack Engineer
02

The Problem

As generative AI workflows become more complex, chaining multiple models (e.g., text-to-image followed by image-to-video) via basic scripts leads to brittle execution, timeout failures, and lost state.

Users needed a visual way to build these pipelines, while the underlying system required a robust engine to execute them as dependency graphs, handle API timeouts, and persist the state of every individual node.

03

How It Works

Rendering architecture...
04

System Architecture

Rendering architecture...
05

Engineering Problems

Workflow Execution & State Persistence

Problem

When a complex workflow fails halfway through, restarting from the beginning wastes expensive AI compute and loses the context of successful upstream tasks.

Solution

Implemented an execution engine that stores individual node state in PostgreSQL. The system queries the database before execution, skipping already-completed nodes and reconstructing the context required for downstream tasks.

Why this approach: Using the database as the source of truth for execution state adds latency compared to in-memory processing, but guarantees complete recovery across distributed workers.

Parallel Dependency Execution

Problem

Executing independent generative tasks sequentially wastes time. The system needed to determine exactly when a task was safe to run.

Solution

Translated the visual canvas into a Directed Acyclic Graph (DAG). The orchestrator evaluates the graph's edges and batches nodes with zero pending dependencies, dispatching them simultaneously to Trigger.dev workers.

06

Deep Dive: The DAG Execution Loop

Rendering architecture...
01

The orchestrator constantly evaluates the graph for unblocked nodes.

02

Independent nodes are dispatched as background jobs to Trigger.dev.

03

As jobs succeed, they update the database, which triggers the next evaluation cycle.

04

Failed jobs isolate their error state, preventing dependent nodes from starting while allowing independent parallel branches to continue.

08

Results

  • Persistent run history allows users to inspect the input/output of any node at any point in time.
  • Graph-based parallel execution significantly reduces total workflow completion time.
  • Serverless dispatch prevents long-running AI tasks from hitting standard HTTP timeout limits.
09

Tech Stack

Next.jsReact FlowTrigger.devPostgreSQLClerk
10

Learnings

State matters more than speed.

For long-running, expensive AI tasks, the guarantee that state is persisted and recoverable is far more valuable than micro-optimizing execution speed.

Decouple orchestration from execution.

Moving the actual LLM API calls into serverless background workers prevents the core routing API from becoming a bottleneck during high concurrency.

Explore the source code.