Building an n8n-Like Workflow Engine in Java | Introducing producer-consumer architecture | Part 7
Ansh
0:00 / 0:00
Building an n8n-Like Workflow Engine in Java | Introducing producer-consumer architecture | Part 7
132 просмотра · 3 нед. назад
Ansh
15 подписчиков
132 просмотра · 3 нед. назад
Continuing to build my own n8n-inspired workflow automation engine using Java and Spring Boot — Part 7.
In this part, I focused on Java concurrency and improving how workflow executions are scheduled and processed.
Instead of directly starting workflow execution from the service layer, I introduced a dedicated queue and worker architecture to separate execution requests from actual workflow processing.
WHAT I WORKED ON
Execution Queue
Implemented a bounded LinkedBlockingQueue with a capacity of 500 execution IDs. Used offer() to detect when the queue is full without blocking indefinitely.
Dedicated Execution Worker
Created an ExecutionWorker to consume queued execution IDs and delegate processing to the ExecutionEngine. Added worker lifecycle management using @PostConstruct and @PreDestroy.
Workflow Execution Architecture
Executions are saved in PostgreSQL with the QUEUED status before being submitted to the queue. The worker processes them, while node-level parallel execution remains handled by the engine's existing executor.
JAVA CONCURRENCY CONCEPTS
Thread pools: newCachedThreadPool() vs. newSingleThreadExecutor()
Producer-consumer architecture
BlockingQueue and LinkedBlockingQueue
SLF4J logging with Logger and LoggerFactory
Executor shutdown and resource cleanup
ARCHITECTURE
Workflow API → WorkflowService → PostgreSQL → Execution Queue → ExecutionWorker → ExecutionEngine → Concurrent Node Execution
WHAT'S NEXT?
The next step is handling queue-full rejection properly so the API can return HTTP 503 Service Unavailable and persist the rejection reason.
I'm also exploring the reliability challenges of in-memory queues, including what happens to queued executions when the application restarts and how database-backed recovery could address this.
TECH STACK
Java, Spring Boot, PostgreSQL, ExecutorService, LinkedBlockingQueue, SLF4J, Hibernate, JPA.
I'm building this project in public to learn backend development through practical implementation and understand how real software systems handle concurrency, scheduling, and reliability.
Follow along as I continue building, testing, debugging, and improving the workflow engine.
#Java #SpringBoot #BackendDevelopment #WorkflowAutomation #JavaConcurrency #ThreadPool #ProducerConsumer #SoftwareEngineering #CodingProject #BuildInPublic