Ever wondered how you can turbocharge your workflow and make your tasks run like a well-oiled machine? Let me introduce you to the powerhouse that is task runners in n8n. Whether you’re a seasoned developer or just dipping your toes into automation, understanding how to configure these task runners can be a game-changer for your productivity. And here’s the kicker: you’ve got two modes to choose from—internal or external. Each has its own set of perks, and I’m going to break it all down for you so you can pick the one that’ll skyrocket your task execution game.
So, what exactly are task runners? Think of them as your trusty sidekicks that execute tasks in a secure and performant way. They’re especially handy for running user-provided JavaScript code. The beauty of task runners lies in their three-component system: the task runner itself, the task broker, and the task requester. The task runner connects to the broker via a websocket connection, and the requester submits tasks to the broker, which the runner then picks up and executes. Once the task is done, the results go back to the requester. Simple, yet incredibly powerful.
Internal vs. External Modes: What’s the Difference?
When it comes to setting up your task runners, you’ve got two paths you can take: internal mode or external mode. Let’s dive into what each of these means for you and your n8n setup.
In internal mode, your n8n instance takes the reins and launches the task runner as a child process. This means n8n is in charge of monitoring and managing the task runner’s life cycle. The task runner shares the same user ID and group ID as n8n, which can be both a blessing and a curse depending on your needs. It’s straightforward and easy to set up, but it might not give you the isolation and scalability you’re looking for.
On the other hand, external mode is where the real magic happens. Here, an external orchestrator like Kubernetes steps in to launch the task runner instead of n8n. This means you can configure the task runner to run as a side-car container next to n8n, giving you that sweet, sweet isolation and scalability. The orchestrator takes over the monitoring and management of the task runner’s life cycle, ensuring it’s fully isolated from your n8n instance. This mode is perfect if you’re looking to scale your operations and keep things running smoothly, no matter how big your workload gets.
Setting Up External Task Runners
Ready to take your task execution to the next level with external task runners? Here’s how you can configure n8n to use them like a pro:
- N8N_RUNNERS_ENABLED=true – This enables task runners.
- N8N_RUNNERS_MODE=external – This tells n8n to use task runners in external mode.
- N8N_RUNNERS_AUTH_TOKEN=<random secure shared secret> – A shared secret that task runners use to connect to the broker.
- N8N_RUNNERS_BROKER_LISTEN_ADDRESS=0.0.0.0 – By default, the task broker only listens to localhost, but you can change this.
The task runner comes bundled within the n8n Docker image, which also includes the task runner launcher. This launcher is a beast—it starts the runner on-demand, keeping memory usage low when there’s no work to do, but with a slight delay (a few hundred milliseconds) during cold-start. Plus, it keeps an eye on the runner, ready to restart it if it gets caught in an infinite loop or other issues.
To run a task runner container from the n8n Docker image, you’ll need to set the following properties:
- command – [‘/usr/local/bin/task-runner-launcher’, ‘javascript’]
- livenessProbe – GET /healthz, port 5680
And don’t forget to set these environment variables for the container:
- N8N_RUNNERS_AUTH_TOKEN=<random secure shared secret> – The shared secret the task runner uses to connect to the broker.
- N8N_RUNNERS_MAX_CONCURRENCY=5 – The number of concurrent tasks the runner can execute.
- N8N_RUNNERS_TASK_BROKER_URI=localhost:5679 – The address of the task broker server within the n8n instance.
- N8N_RUNNERS_AUTO_SHUTDOWN_TIMEOUT=15 – Number of seconds of inactivity to wait before shutting down the task runner process.
- NODE_OPTIONS=–max-old-space-size=<limit> – The memory limit for the task runner Node.js process.
The launcher will automatically start the runner again when there are new tasks to execute. If you want to disable automatic shutdown, just set the timeout to 0. And remember, the memory limit for the task runner should be lower than the container’s limit, so the launcher can keep monitoring the runner without running out of memory itself.
Why Choose External Mode?
So, why should you go for external mode? It’s all about isolation and scalability. When you use external mode, each n8n container (main and workers) gets its own task runner, ensuring that your tasks are executed in a completely isolated environment. This is crucial if you’re dealing with sensitive data or if you want to scale your operations without running into resource bottlenecks.
External mode also gives you the flexibility to use orchestration tools like Kubernetes, which can manage your task runners like a boss. This means you can scale up or down based on your workload, ensuring that your n8n setup is always running at peak efficiency. Plus, with external mode, you’re not tied to the limitations of your n8n instance—you can let your task runners run wild and free, handling whatever tasks you throw at them.
Wondering how this works in practice? Let me give you a quick example. Imagine you’re running a large-scale automation workflow that involves processing thousands of records. With internal mode, you might run into performance issues as your n8n instance struggles to keep up. But with external mode, you can spin up multiple task runner containers, each handling a chunk of the workload, ensuring that everything runs smoothly and efficiently.
And here’s a little tip from my own experience: I’ve set up external task runners for several clients, and the difference in performance and scalability is night and day. It’s like going from a bicycle to a Ferrari—your tasks will fly through the workflow, leaving you more time to focus on what really matters: growing your business.
So, what are you waiting for? It’s time to configure your task runners and take your n8n setup to the next level. Whether you choose internal or external mode, you’re on your way to executing tasks like a pro. And if you’re hungry for more insights on optimizing your workflow, why not check out our other resources? Ready to boost your automation game? Let’s do this!