Automation

How to Use n8n Queue Mode to Scale Workers

Learn step-by-step how to set up n8n in queue mode and scale workers for efficient task processing.

4 min read

Learn how to efficiently scale n8n by enabling queue mode and deploying multiple workers using Docker. Queue mode separates the main n8n instance from workers, allowing workflows to process in parallel without being blocked by long tasks.

Prerequisites for Setting Up n8n Queue Mode

Before beginning the setup for n8n queue mode, make sure you meet the following requirements:

prerequisites

  • A server or VPS with Docker installed.
  • Basic familiarity with n8n workflow configurations.
  • Installation of Redis as the queue manager.
  • Hosting from providers like Hostinger or equivalent services.

Steps to Set Up n8n Queue Mode

Follow these steps to enable queue mode and scale n8n with multiple workers:

steps

  1. Prepare Your Server Environment: Ensure docker and docker-compose are installed on your server. Install Redis for queue management:

    bash
    sudo apt-get update
    sudo apt-get install redis
    sudo systemctl start redis
  2. Install n8n and Configure the Main Instance: Create a docker-compose.yml file for the main n8n instance. Configure Redis and database connections:

    yaml
    version: '3'
    services:
      n8n:
        image: n8nio/n8n
        ports:
          - 5678:5678
        environment:
          - EXECUTIONS_PROCESS=main
          - QUEUE_MODE=true
          - REDIS_HOST=redis
          - DB_TYPE=postgresdb # Adapt if using a different DB
        restart: always
      redis:
        image: redis:alpine
        restart: always

    Start the services:

    bash
    docker-compose up -d
  3. Launch Worker Instances: Add worker containers in the same docker-compose.yml to facilitate parallel execution:

    yaml
      worker-1:
        image: n8nio/n8n
        environment:
          - EXECUTIONS_PROCESS=queue
          - N8N_MODE=worker
          - REDIS_HOST=redis
        depends_on:
          - redis
        restart: always
    
      worker-2:
        image: n8nio/n8n
        environment:
          - EXECUTIONS_PROCESS=queue
          - N8N_MODE=worker
          - REDIS_HOST=redis
        depends_on:
          - redis
        restart: always

    Restart Docker to apply changes:

    bash
    docker-compose down
    docker-compose up -d
  4. Verify Worker Activity: Access your Redis instance to verify queued jobs:

    bash
    redis-cli
    KEYS *

    Run test workflows to ensure proper execution and monitor resource usage with docker stats.

Common Mistakes and Troubleshooting

When configuring n8n queue mode, avoid the following:

Verifying the Setup

You can validate your n8n queue mode setup by testing with actual workflows.

steps

  1. Run a Workflow with Large Data: Configure a workflow to process large numbers of items (e.g., 10,000 rows). Monitor the execution time.

  2. Check Parallel Execution: Log into Redis and view active job queues:

    bash
    redis-cli
    LRANGE bull:queue_name:active 0 -1
  3. Monitor Resource Utilization: Use the following command to inspect Docker container stats:

    bash
    docker stats

    Confirm that each worker is actively processing jobs.

Benefits of Scaling with Queue Mode

Switching to queue mode offers distinct advantages:

comparison

Default Single Process Mode

  • Sequential task handling.
  • Webhooks may be blocked during long workflow executions.

Queue Mode with Workers

  • Allows parallel processing of tasks.
  • Improves stability under high load.
  • Enables flexible retry mechanisms for failures.

Making the Choice Between Hostinger and Other VPS Providers

Choosing Hosting Providers

  • Choose Hostinger if you need simplified setup with ample documentation and support.
  • Evaluate competitors for cost vs. resource availability.
  • Ensure hosting plans support sufficient CPU and memory for your scaling needs.

FAQ

How does queue mode scale n8n processes?

Queue mode separates workflow orchestration (main instance) from task execution (workers). This allows tasks to be processed in parallel, improving throughput and scalability.

Can I use queue mode without Redis?

No, Redis is required to manage the job queue. It acts as the intermediary between the main n8n instance and worker nodes.

What hardware do I need for n8n queue mode?

A multi-core server is recommended. Allocate at least one CPU core per worker instance for optimal performance. For handling large datasets, ensure adequate memory is available as well.


Official reference: n8n documentation.