Перейти к содержимому

Building an n8n-Like Workflow Engine in Java | Graph Validation & Merge Nodes | Part 11

Ansh

0:00 / 0:00

Building an n8n-Like Workflow Engine in Java | Graph Validation & Merge Nodes | Part 11

71 просмотр · 2 нед. назад
Ansh
15 подписчиков
71 просмотр · 2 нед. назад
I'm building an n8n-inspired workflow automation engine from scratch using Java and Spring Boot. This is Part 11 of my build-in-public series, where I share my implementation process, technical challenges, architectural decisions, and lessons learned while building a real backend project. In this episode, I worked on workflow graph validation and investigated how parallel execution can create data conflicts when multiple nodes produce the same output key. I also explored the functionality of n8n's Merge node and planned how to implement similar behavior in my own workflow engine. WORKFLOW GRAPH VALIDATION Before executing a workflow, the engine needs to verify that its structure is valid. Invalid connections, missing nodes, or an absent start node can cause problems during scheduling and execution. To address this, I created a dedicated WorkflowValidator class and integrated it into the ExecutionEngine. The engine now validates the workflow before beginning node scheduling. The validation checks include: The workflow must not be null. The connections list must not be null. The workflow must contain at least one node. At least one start node must exist. Every connection must reference valid source and target nodes. Self-connections are rejected. Source and target nodes must belong to the same workflow. This keeps validation separate from execution logic and provides a dedicated place to verify the workflow structure before execution begins. PARALLEL EXECUTION AND DATA CONFLICTS Consider a workflow where two nodes execute in parallel. Node 1 produces a message field containing hello. Node 2 produces a message field containing world. If both outputs are combined into a single flat map, one value can overwrite the other. This creates a data conflict and may prevent downstream nodes from accessing the information they need. I investigated this problem in the existing execution-context and dependency-resolution logic. The key challenge is preserving data from parallel branches and defining what should happen when multiple nodes produce the same field. THE N8N MERGE NODE A Merge node allows data from multiple upstream branches to be combined before execution continues downstream. I explored two merge strategies for my implementation: Append: Append items from multiple inputs into a combined collection. Combine by Position: Combine items based on their corresponding positions or indexes. These strategies behave differently, so the workflow engine needs explicit merge rules rather than silently overwriting conflicting values. PLANNING THE MERGE NODE The next step is to introduce a dedicated MERGE node type into the execution engine. This will require defining how the node receives outputs from multiple upstream nodes, determines when its dependencies are ready, applies the selected merge strategy, and passes the resulting data to downstream nodes. The Merge node is planned work and has not yet been completed. This episode focuses on workflow validation, investigating parallel data conflicts, and preparing the architecture for the next implementation stage. TECH STACK Java Spring Boot Spring Data JPA and Hibernate PostgreSQL REST APIs ExecutorService Concurrent workflow execution Workflow graph validation Dependency-aware execution engine WHY I'M BUILDING THIS PROJECT I'm building this project in public to improve my backend engineering skills through practical implementation. Instead of only following tutorials, I'm working through the challenges involved in designing and implementing a workflow automation engine. This project helps me explore Java concurrency, execution scheduling, dependency management, database persistence, workflow orchestration, and the design decisions involved in building reliable backend systems. Follow along as I continue building the engine, solving problems, and learning through real implementation. UP NEXT Implementing the dedicated Merge node, defining its input behavior, and integrating merge strategies into the workflow execution engine. #Java #SpringBoot #BackendDevelopment #WorkflowAutomation #BuildInPublic #SoftwareEngineering #PostgreSQL #Java #SpringBoot #BackendDevelopment #WorkflowAutomation #WorkflowEngine #GraphValidation #ParallelExecution #MergeNode #SystemDesign #BuildInPublic