Back to articles
Technology Insight

Scaling n8n to Millions of Webhooks: A Step-by-Step Guide to Deploying Queue Mode on Docker Swarm

June 6, 2026

Introduction: The Scalability Challenge in Enterprise Automation

In modern enterprise architectures, event-driven automation has transitioned from a convenience to a mission-critical necessity. As platforms ingest data from dozens of SaaS tools, IoT devices, and internal microservices, the volume of webhooks can explode exponentially. Processing hundreds of requests per second requires a robust infrastructure capable of absorbing traffic spikes without losing data or degrading performance.

While n8n is an exceptionally powerful workflow automation tool, its default standalone configuration executes all processes within a single instance. When subjected to an influx of millions of webhooks daily, this single-instance model faces severe bottlenecks: CPU throttling, memory exhaustion, and catastrophic downtime. To overcome these limitations, enterprises must transition to n8n Queue Mode and orchestrate their infrastructure using Docker Swarm.

This comprehensive guide explores the architecture, prerequisites, and step-by-step implementation strategies required to deploy a production-grade, highly available n8n Queue Mode cluster capable of seamlessly handling millions of webhooks every single day.

Understanding n8n Queue Mode Architecture

Before diving into configuration files, it is vital to understand how n8n distributes workloads in Queue Mode. Unlike the standard deployment, Queue Mode decouples the user interface, the webhook reception layer, and the heavy lifting of workflow execution into specialized roles.

The Core Components

  • Main Instance (Editor): Serves the frontend UI, manages user authentication, handles workflow configurations, and orchestrates periodic cron jobs. Only one main instance runs in the cluster.
  • Webhook Processors: Dedicated, ultra-lightweight n8n instances optimized solely for receiving incoming HTTP webhook requests. They do not execute workflows; instead, they immediately offload the execution payload to a message queue and return a fast 200 OK response to the sender.
  • Worker Nodes: Independent n8n processes that continuously poll the message queue, pull pending execution tasks, and execute the actual workflow logic (fetching data, transforming payloads, calling APIs). Workers can be dynamically scaled up or down based on queue depth.
  • Redis (Message Broker): The high-performance, in-memory data store that acts as the communication backbone, buffering incoming jobs and distributing them to available workers via BullMQ.
  • PostgreSQL (Shared Database): The centralized state repository storing workflow definitions, user credentials, execution logs, and environment variables. All n8n instances connect to this database.
Strategic Insight: By isolating Webhook Processors from Workers, a sudden spike in incoming webhooks will only increase the Redis queue length. It will never crash the ingestion layer, ensuring absolute data retention and system reliability.

Why Docker Swarm for n8n Scaling?

While Kubernetes is often praised for large-scale container orchestration, Docker Swarm presents a highly compelling alternative for deploying n8n in production. Its advantages include:

  1. Operational Simplicity: Docker Swarm is built directly into the Docker Engine. There are no complex control planes, ingress controllers, or overlay plugins to manually configure.
  2. Resource Efficiency: Swarm consumes significantly less overhead than Kubernetes, leaving more underlying hardware resources available for running intensive n8n data transformations.
  3. Native Declarative Scaling: Scaling your n8n workers or webhook processors from 2 to 20 instances requires a single, declarative CLI command or configuration updates within a standard docker-compose.yml syntax.

Prerequisites and Infrastructure Planning

To successfully handle millions of webhooks daily, your underlying infrastructure must be provisioned with high availability in mind. At a minimum, a production-grade Swarm cluster requires:

  • Three Manager Nodes: To maintain Raft consensus and ensure cluster management availability.
  • Two or more Worker Nodes: To host the actual n8n containers and ensure application-level fault tolerance.
  • A Managed Database & Cache: For production workloads, it is strongly advised to utilize managed cloud services for PostgreSQL and Redis (e.g., AWS RDS, DigitalOcean Managed Databases) to ensure automated backups, multi-AZ replication, and failover capabilities.

Step-by-Step Production Deployment Guide

Below is the complete blueprint for setting up n8n Queue Mode within a Docker Swarm environment using a unified stack definition file.

Step 1: Setting Up the Docker Swarm Overlay Network

First, log into your primary Swarm manager node via SSH and create an encrypted overlay network to facilitate secure, cross-node communication between your containers:

docker network create --driver overlay --attachable --opt encrypted n8n_network

Step 2: Drafting the Production Docker Swarm Stack (docker-compose.yml)

Create a deployment file named n8n-stack.yml. This configuration specifies the environment variables, scaling policies, and operational constraints required for optimal execution.

version: '3.8'

services:
  n8n-main:
    image: docker.n8n.io/n8nio/n8n:latest
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=your-managed-db-host
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=n8n_prod
      - DB_POSTGRESDB_USER=n8n_user
      - DB_POSTGRESDB_PASSWORD=secure_password_here
      - EXECUTIONS_MODE=queue
      - QUEUE_BULL_REDIS_HOST=your-redis-host
      - QUEUE_BULL_REDIS_PORT=6379
      - N8N_ENCRYPTION_KEY=your_super_secret_encryption_key
      - N8N_HOST=n8n.yourdomain.com
      - N8N_PORT=5678
    networks:
      - n8n_network
    deploy:
      mode: replicated
      replicas: 1
      placement:
        constraints: [node.role == manager]

  n8n-webhook:
    image: docker.n8n.io/n8nio/n8n:latest
    command: /bin/sh -c "n8n webhook"
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=your-managed-db-host
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=n8n_prod
      - DB_POSTGRESDB_USER=n8n_user
      - DB_POSTGRESDB_PASSWORD=secure_password_here
      - EXECUTIONS_MODE=queue
      - QUEUE_BULL_REDIS_HOST=your-redis-host
      - QUEUE_BULL_REDIS_PORT=6379
      - N8N_ENCRYPTION_KEY=your_super_secret_encryption_key
    networks:
      - n8n_network
    deploy:
      mode: replicated
      replicas: 3
      update_config:
        parallelism: 1
        delay: 10s
      restart_policy:
        condition: on-failure

  n8n-worker:
    image: docker.n8n.io/n8nio/n8n:latest
    command: /bin/sh -c "n8n worker"
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=your-managed-db-host
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=n8n_prod
      - DB_POSTGRESDB_USER=n8n_user
      - DB_POSTGRESDB_PASSWORD=secure_password_here
      - EXECUTIONS_MODE=queue
      - QUEUE_BULL_REDIS_HOST=your-redis-host
      - QUEUE_BULL_REDIS_PORT=6379
      - N8N_ENCRYPTION_KEY=your_super_secret_encryption_key
    networks:
      - n8n_network
    deploy:
      mode: replicated
      replicas: 4
      resources:
        limits:
          cpus: '1.0'
          memory: 1024M
        reservations:
          cpus: '0.25'
          memory: 256M
      restart_policy:
        condition: on-failure

networks:
  n8n_network:
    external: true

Step 3: Deploying the Stack to the Cluster

Execute the following deployment command on your Swarm Manager node to push your configuration live:

docker stack deploy -c n8n-stack.yml n8n_cluster

Docker Swarm will instantly read the file, download the official images, create individual tasks, and cleanly distribute the specified replicas across all available cluster nodes.

Critical Performance Optimization Strategies

Simply putting n8n into Queue Mode isn't enough to sustain millions of daily transactions. You must systematically fine-tune your configuration to avoid internal friction.

1. Implement Drastic Data Pruning

By default, n8n saves every execution log to the database. At millions of executions, your database will swell by gigabytes daily, drastically degrading performance. Enforce aggressive execution data pruning by appending these environment variables to all services:

  • EXECUTIONS_DATA_PRUNE=true
  • EXECUTIONS_DATA_MAX_AGE=48 (Retain data for only 48 hours)
  • EXECUTIONS_DATA_PRUNE_TIMEOUT=3600 (Prune stale data hourly)
  • EXECUTIONS_DATA_SAVE_ON_SUCCESS=none (Do not save successful logs if unnecessary)

2. Configure Reverse Proxy and Ingress Load Balancing

To safely route external webhook traffic into your Swarm cluster, set up an enterprise-grade reverse proxy such as Traefik or NGINX Plus at the edge of your infrastructure. Ensure that any traffic sent to /webhook/* is directed exclusively to the pool of n8n-webhook containers, while standard dashboard routes point to n8n-main.

3. Monitor Redis Queue Metrics

Keep a vigilant eye on your message broker. If your n8n-worker nodes cannot keep up with incoming payloads, the Redis memory footprint will rise dramatically. Implement monitoring stacks using Prometheus and Grafana to track metrics such as active workers, pending jobs, and job processing latency.

Conclusion

Deploying n8n in Queue Mode via Docker Swarm provides an incredibly efficient, highly resilient, and budget-friendly platform for high-throughput automation. By decoupling ingestion from workflow execution, utilizing a high-speed Redis queue, and applying strict database pruning rules, your architecture will comfortably sustain millions of daily webhooks without breaking a sweat. As your enterprise integration needs grow, scaling up is as simple as executing a single command to deploy more workers, ensuring your automation infrastructure scales seamlessly alongside your business.