When You Need It
A single n8n container, as in self-hosting n8n on a VPS, runs every execution in one process. That is plenty for most teams. Queue mode is worth the extra parts when long or heavy workflows delay others, when webhooks arrive in bursts, or when you want executions to carry on if one process fails.
| Part | What it does | How many |
|---|---|---|
| Main instance | Editor, triggers, schedules; puts executions on the queue | One (several only with multi-main) |
| Redis | The queue between main and workers | One |
| PostgreSQL | Workflows, credentials, execution history | One, with backups |
| Workers | Run the executions | As many as you need |
| Webhook processors | Answer production webhooks | Optional |
1. Move Your Workflows to PostgreSQL
If n8n is running on SQLite now, export everything with n8n's command line before switching, then import it into the new instance once it is running on PostgreSQL:
docker compose exec n8n n8n export:workflow --backup --output=/home/node/.n8n/backup/workflows/ docker compose exec n8n n8n export:credentials --backup --output=/home/node/.n8n/backup/credentials/
The credentials export is encrypted with your current encryption key. Copy that key from /home/node/.n8n/config in the old container: the new setup must use the same one, or the imported credentials cannot be read. Check n8n's CLI documentation for your version, since the export commands have gained options over time.
2. Write the Compose File
In ~/n8n-queue/.env, with your own values:
N8N_ENCRYPTION_KEY=the-key-from-step-1 # or: openssl rand -hex 32 for a new install POSTGRES_PASSWORD=a-long-random-password REDIS_PASSWORD=another-long-random-password
And ~/n8n-queue/compose.yaml:
x-n8n: &n8n
image: docker.n8n.io/n8nio/n8n
restart: unless-stopped
environment: &n8n-env
EXECUTIONS_MODE: queue
N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY}
DB_TYPE: postgresdb
DB_POSTGRESDB_HOST: postgres
DB_POSTGRESDB_DATABASE: n8n
DB_POSTGRESDB_USER: n8n
DB_POSTGRESDB_PASSWORD: ${POSTGRES_PASSWORD}
QUEUE_BULL_REDIS_HOST: redis
QUEUE_BULL_REDIS_PORT: "6379"
QUEUE_BULL_REDIS_PASSWORD: ${REDIS_PASSWORD}
GENERIC_TIMEZONE: America/New_York
depends_on: [postgres, redis]
services:
postgres:
image: postgres:16
restart: unless-stopped
environment:
POSTGRES_DB: n8n
POSTGRES_USER: n8n
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
volumes:
- pg_data:/var/lib/postgresql/data
redis:
image: redis:7-alpine
restart: unless-stopped
command: redis-server --requirepass ${REDIS_PASSWORD}
volumes:
- redis_data:/data
n8n:
<<: *n8n
ports:
- "127.0.0.1:5678:5678" # reached through Nginx only
environment:
<<: *n8n-env
N8N_HOST: n8n.example.com
N8N_PROTOCOL: https
N8N_WEBHOOK_URL: https://n8n.example.com/
WEBHOOK_URL: https://n8n.example.com/ # the name before n8n 2.30
worker:
<<: *n8n
command: worker --concurrency=10
volumes:
pg_data:
redis_data:cd ~/n8n-queue docker compose up -d docker compose logs -f worker # the worker reports it is waiting for jobs
Nothing but the main instance publishes a port, and only to the server itself. Put Nginx and HTTPS in front of it as in the single-server guide, then import the workflows and credentials from step 1.
3. Add Workers
On the same server, more workers are one command:
docker compose up -d --scale worker=3
Watch memory with docker stats while your heaviest workflows run: each worker is a full n8n process. To run workers on another server, copy the x-n8n block and the worker service there, point DB_POSTGRESDB_HOST and QUEUE_BULL_REDIS_HOST at the first server, and keep PostgreSQL and Redis off the public internet. Between our servers in the same location, private networking carries that traffic; elsewhere, use WireGuard.
Manual runs from the editor still execute on the main instance. Set OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS=true on it to send them to workers too.
4. Optional: Webhook Processors
Webhook processors take production webhook calls off the main instance. Add a service like the worker with command: webhook and 127.0.0.1:5679:5678 as its port, then route by path in Nginx. Test webhooks (/webhook-test/) must still reach the main instance:
location ~ ^/(webhook|webhook-waiting)/ {
proxy_pass http://127.0.0.1:5679;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location / {
proxy_pass http://127.0.0.1:5678; # editor, API and /webhook-test/
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}With several processors, list them in an Nginx upstream block. To stop the main instance answering production webhooks itself, set N8N_DISABLE_PRODUCTION_MAIN_PROCESS=true on it.
5. Health Checks and Updates
- Health: set
QUEUE_HEALTH_CHECK_ACTIVE=trueon workers and they answer/healthz(running) and/healthz/readiness(database and Redis connected) on port 5678. Uptime Kuma can watch them. - Updates: main and workers should run the same n8n version. Pull and restart them together with
docker compose pull && docker compose up -d, after a database backup. - Backups: PostgreSQL now holds everything; dump it nightly as in backing up a database to S3, and keep the encryption key somewhere safe and separate.
- Binary data: in queue mode, files passing through workflows are kept in the database by default, which grows it. Workflows that handle large files are better kept small, or moved to external storage if your n8n licence includes it.
Beyond One Main Instance
Queue mode leaves one main instance. n8n's multi-main setup runs several behind a load balancer with sticky sessions, all in queue mode on the same PostgreSQL and Redis, with N8N_MULTI_MAIN_SETUP_ENABLED=true. It is a self-hosted Enterprise feature and needs a licence. For most teams, queue mode on a dedicated server or two VPSes, plus tested backups, is the practical stopping point.