Skip to content

Tutorial

How to configure n8n queue mode with Redis on a VPS

Once self-hosted n8n handles dozens of webhooks per minute or runs heavy AI and spreadsheet workflows, a single container slows down the editor and stalls incoming triggers. This guide sets up n8n in queue mode on an Ubuntu 24.04 VPS with Docker Compose, splitting the main instance, a Redis queue broker, two workers with dedicated external task runners (n8nio/runners), PostgreSQL 18 and automatic HTTPS via Caddy.

On this page
  1. When to enable queue mode
  2. How the architecture fits together
  3. What you need
  4. Create the project folder and `.env` secrets
  5. Create the `Caddyfile`
  6. Build `docker-compose.yml` with Redis, workers and runners
  7. Start the stack and verify queue, workers and runners
  8. When to add a dedicated webhook processor
  9. Common queue mode errors
  10. Next steps

All environment variables, commands and defaults follow the official n8n 2.48.7 documentation (EXECUTIONS_MODE=queue, N8N_RUNNERS_MODE=external, OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS=true and QUEUE_HEALTH_CHECK_ACTIVE=true), building on our single-instance guide How to install n8n with Docker on a VPS.

When to enable queue mode

In default (regular) mode, one Node.js process serves the UI, receives webhooks, triggers schedules and runs every workflow node. When a heavy workflow blocks the event loop or spikes memory, the editor freezes and incoming webhooks time out.

In queue mode, the main instance accepts triggers, writes the execution record to PostgreSQL and pushes only the execution ID into Redis. Dedicated worker containers pull jobs in parallel and report results back through PostgreSQL and Redis:

  • Stay on regular mode if you run a handful of light workflows per hour on a 4 GB or 8 GB VPS.
  • Move to queue mode when webhooks lag during long executions, the editor stutters under load or you need parallel worker scaling.
Automation workload Recommended topology vCPU RAM SSD
Light workflows and occasional webhooks Regular mode (1 n8n + 1 runner) 2–4 4–8 GB 50–100 GB
Frequent webhooks (WhatsApp, CRM, AI agents) Queue mode (1 main + 2 workers) 6 12 GB 200 GB
High bursts, Evolution API co-hosted or 4+ parallel workers Queue mode + webhook processor 8 24 GB 300+ GB

If you also host Evolution API or Coolify on the same server, see the full memory breakdown in How much RAM and vCPU for n8n, Evolution API and Coolify.

How the architecture fits together

In this layout, no database, Redis or worker port is published on the host. Only Caddy listens on ports 80 and 443; every other service communicates exclusively over the private Docker Compose network:

n8n queue mode architecture on an Ubuntu VPS with Caddy on ports 80 and 443, main instance, Redis queue, PostgreSQL 18 and two workers with external task runners

Three architectural choices prevent the most common n8n 2.x queue-mode pitfalls:

  1. OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS=true: manual workflow runs are also queued to workers via Redis. That keeps main light for the editor, API, webhooks and timers without needing its own n8nio/runners sidecar.
  2. One dedicated n8nio/runners sidecar per worker: per official n8n documentation, every worker running N8N_RUNNERS_MODE=external needs its own runner container pointing to http://<worker-service>:5679 with the matching N8N_RUNNERS_AUTH_TOKEN. The image tag for n8n and runners must match exactly.
  3. Shared N8N_ENCRYPTION_KEY across all instances: main and every worker must receive the exact same key so workers can decrypt credentials stored in PostgreSQL.

What you need

  • An Ubuntu 24.04 64-bit VPS with Docker Engine and the Compose plugin (v2.20+), plus ufw allowing only SSH (22/tcp), 80/tcp and 443 (TCP/UDP).
  • A subdomain with an A record pointing to the VPS IPv4 address (n8n.example.com in the examples below).
  • An email address for Caddy's ACME certificate account.

If Docker is not installed yet, follow the preparation steps in How to install n8n with Docker on a VPS.

Create the project folder and .env secrets

Create a directory for the stack and generate four strong random secrets — for N8N_ENCRYPTION_KEY, N8N_RUNNERS_AUTH_TOKEN, POSTGRES_PASSWORD and REDIS_PASSWORD:

bash
mkdir -p ~/n8n-queue && cd ~/n8n-queue
for i in 1 2 3 4; do openssl rand -hex 32; done

Save them in .env and lock down file permissions:

.env
N8N_VERSION=2.48.7
N8N_DOMAIN=n8n.example.com
[email protected]
GENERIC_TIMEZONE=UTC

N8N_ENCRYPTION_KEY=paste-first-secret-here
N8N_RUNNERS_AUTH_TOKEN=paste-second-secret-here

POSTGRES_USER=n8n
POSTGRES_PASSWORD=paste-third-secret-here
POSTGRES_DB=n8n

REDIS_PASSWORD=paste-fourth-secret-here
WORKER_CONCURRENCY=10
bash
chmod 600 .env

Create the Caddyfile

Caddy provisions and renews TLS automatically and proxies HTTPS traffic to n8n-main:5678, with flush_interval -1 so streaming responses and editor events are never buffered:

Caddyfile
{
	email {$ACME_EMAIL}
}

{$N8N_DOMAIN} {
	reverse_proxy n8n-main:5678 {
		flush_interval -1
	}
}

Build docker-compose.yml with Redis, workers and runners

This Compose file uses a YAML anchor (x-n8n-common) so n8n-main, n8n-worker-1 and n8n-worker-2 share the exact same image tag, PostgreSQL connection, Redis broker, encryption key, pruning settings and external task runner configuration:

docker-compose.yml
x-n8n-common: &n8n-common
  image: docker.n8n.io/n8nio/n8n:${N8N_VERSION}
  restart: always
  environment:
    - N8N_HOST=${N8N_DOMAIN}
    - N8N_PORT=5678
    - N8N_PROTOCOL=https
    - N8N_WEBHOOK_URL=https://${N8N_DOMAIN}/
    - N8N_PROXY_HOPS=1
    - N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
    - N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
    - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
    - TZ=${GENERIC_TIMEZONE}
    - DB_TYPE=postgresdb
    - DB_POSTGRESDB_HOST=postgres
    - DB_POSTGRESDB_PORT=5432
    - DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
    - DB_POSTGRESDB_USER=${POSTGRES_USER}
    - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
    - EXECUTIONS_MODE=queue
    - OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS=true
    - QUEUE_BULL_REDIS_HOST=redis
    - QUEUE_BULL_REDIS_PORT=6379
    - QUEUE_BULL_REDIS_PASSWORD=${REDIS_PASSWORD}
    - QUEUE_HEALTH_CHECK_ACTIVE=true
    - N8N_GRACEFUL_SHUTDOWN_TIMEOUT=30
    - N8N_RUNNERS_MODE=external
    - N8N_RUNNERS_AUTH_TOKEN=${N8N_RUNNERS_AUTH_TOKEN}
    - N8N_RUNNERS_BROKER_LISTEN_ADDRESS=0.0.0.0
    - EXECUTIONS_DATA_PRUNE=true
    - EXECUTIONS_DATA_MAX_AGE=168
    - EXECUTIONS_DATA_PRUNE_MAX_COUNT=20000
  depends_on:
    postgres:
      condition: service_healthy
    redis:
      condition: service_healthy

services:
  caddy:
    image: caddy:2.11
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    environment:
      - N8N_DOMAIN=${N8N_DOMAIN}
      - ACME_EMAIL=${ACME_EMAIL}
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy_data:/data
      - caddy_config:/config
    depends_on:
      - n8n-main

  postgres:
    image: postgres:18
    restart: always
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=${POSTGRES_DB}
      - PGDATA=/var/lib/postgresql/data
    volumes:
      - db_storage:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -h localhost -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
      interval: 5s
      timeout: 5s
      retries: 10

  redis:
    image: redis:7-alpine
    restart: always
    environment:
      - REDIS_PASSWORD=${REDIS_PASSWORD}
      - REDISCLI_AUTH=${REDIS_PASSWORD}
    command: ["sh", "-c", 'exec redis-server --appendonly yes --requirepass "$$REDIS_PASSWORD"']
    volumes:
      - redis_storage:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 5s
      retries: 10

  n8n-main:
    <<: *n8n-common
    volumes:
      - n8n_data:/home/node/.n8n
    healthcheck:
      test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:5678/healthz || exit 1"]
      interval: 10s
      timeout: 5s
      retries: 10

  n8n-worker-1:
    <<: *n8n-common
    command: ["worker", "--concurrency=${WORKER_CONCURRENCY}"]
    healthcheck:
      test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:5678/healthz/readiness || exit 1"]
      interval: 10s
      timeout: 5s
      retries: 10

  n8n-runner-1:
    image: n8nio/runners:${N8N_VERSION}
    restart: always
    environment:
      - N8N_RUNNERS_AUTH_TOKEN=${N8N_RUNNERS_AUTH_TOKEN}
      - N8N_RUNNERS_TASK_BROKER_URI=http://n8n-worker-1:5679
    depends_on:
      n8n-worker-1:
        condition: service_healthy

  n8n-worker-2:
    <<: *n8n-common
    command: ["worker", "--concurrency=${WORKER_CONCURRENCY}"]
    healthcheck:
      test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:5678/healthz/readiness || exit 1"]
      interval: 10s
      timeout: 5s
      retries: 10

  n8n-runner-2:
    image: n8nio/runners:${N8N_VERSION}
    restart: always
    environment:
      - N8N_RUNNERS_AUTH_TOKEN=${N8N_RUNNERS_AUTH_TOKEN}
      - N8N_RUNNERS_TASK_BROKER_URI=http://n8n-worker-2:5679
    depends_on:
      n8n-worker-2:
        condition: service_healthy

volumes:
  caddy_data:
  caddy_config:
  db_storage:
  redis_storage:
  n8n_data:

Key details in this configuration:

  • No N8N_RUNNERS_ENABLED: deprecated since n8n 2.0; setting N8N_RUNNERS_MODE=external enables external task runners cleanly without deprecation warnings.
  • QUEUE_HEALTH_CHECK_ACTIVE=true: exposes /healthz and /healthz/readiness on port 5678 inside each worker. /healthz/readiness only returns 200 once both PostgreSQL and Redis connections are healthy, so each n8n-runner-* waits for its worker before connecting.
  • --concurrency=10: n8n's default. Official guidance recommends keeping concurrency at 5 or higher — spinning up many low-concurrency workers can exhaust PostgreSQL's connection pool.
  • Password-protected, private Redis: REDISCLI_AUTH lets the healthcheck run redis-cli ping cleanly without leaking the password in warnings, and --appendonly yes persists queued jobs across restarts.

Start the stack and verify queue, workers and runners

Validate the Compose YAML first, then start all containers:

bash
cd ~/n8n-queue
sudo docker compose config --quiet
sudo docker compose up -d
sudo docker compose ps

Verify four things right after startup:

1. Health of main and workers

Confirm postgres, redis, n8n-main, n8n-worker-1 and n8n-worker-2 report Up (healthy) in docker compose ps, then check external HTTPS:

bash
curl -fsS https://n8n.example.com/healthz

2. External task runner connections

Check the runner logs to confirm each sidecar connected to its worker's task broker without authentication errors:

bash
sudo docker compose logs --tail=30 n8n-runner-1 n8n-runner-2

You should see the launcher starting the JavaScript and Python runners and connecting to http://n8n-worker-1:5679 and http://n8n-worker-2:5679.

3. Live execution flowing through Redis

Open https://n8n.example.com, create a small workflow with a Webhook (or Manual Trigger) connected to a Code node returning { ok: true, host: $env.HOSTNAME }, and trigger it a few times while tailing both workers:

bash
sudo docker compose logs -f n8n-worker-1 n8n-worker-2

In a second SSH session, confirm Bull queue keys exist in Redis:

bash
sudo docker compose exec redis redis-cli KEYS "bull:*"

When executions show up in n8n-worker-1 or n8n-worker-2 (instead of running on n8n-main) and the Code node succeeds, queue mode and external task runners are working end to end.

4. Exposed host ports

Verify only 80 and 443 are bound on the host:

bash
sudo ss -tulpn | grep -E ':(80|443|5432|5678|5679|6379)\b'

If 5432, 5678, 5679 or 6379 appears on 0.0.0.0, remove any accidental ports: mapping. See why in Docker port still open with ufw.

When to add a dedicated webhook processor

If your bottleneck is incoming HTTP volume rather than workflow execution time (for example, dozens of Evolution API instances firing WhatsApp webhooks simultaneously), add a dedicated webhook processor container:

  1. Add an n8n-webhook service reusing <<: *n8n-common with command: ["webhook"].
  2. Set N8N_DISABLE_PRODUCTION_MAIN_PROCESS=true on n8n-main so the editor process stops competing with production webhook traffic.
  3. Update Caddyfile to route /webhook/* and /webhook-waiting/* to n8n-webhook:5678, while keeping /webhook-test/* and all UI/API routes on n8n-main:5678:
Caddyfile
{$N8N_DOMAIN} {
	@prod_webhooks path /webhook/* /webhook-waiting/*
	handle @prod_webhooks {
		reverse_proxy n8n-webhook:5678 {
			flush_interval -1
		}
	}
	handle {
		reverse_proxy n8n-main:5678 {
			flush_interval -1
		}
	}
}

Common queue mode errors

  • Code node hangs on "Waiting for task runner" or times out: a worker is missing its n8nio/runners sidecar, N8N_RUNNERS_BROKER_LISTEN_ADDRESS=0.0.0.0 was omitted on the worker, or the n8nio/runners tag does not match N8N_VERSION.
  • Credentials could not be decrypted on workers: a worker started with a different N8N_ENCRYPTION_KEY than n8n-main (or without the variable set).
  • Executions stay stuck in "Queued": check that workers are running (docker compose ps), QUEUE_BULL_REDIS_PASSWORD matches Redis, and Redis has not hit its memory limit.
  • The response is too large to be sent back from the worker: for Respond to Webhook workflows, workers relay responses back to main via Redis (default limit N8N_WEBHOOK_RESPONSE_RELAY_SIZE_MAX=64 MiB). On n8n 2.34+, enable N8N_WEBHOOK_RESPONSE_RELAY_OFFLOAD_ENABLED=true on workers alongside shared binary storage (database, s3 or azure).
  • PostgreSQL rejects connections (too many clients already): too many worker containers are competing for PostgreSQL connections. Reduce worker count and prefer 2 or 3 workers with --concurrency=10.

Next steps