---
title: "Deploy n8n with Workers (Queue Mode + Redis + Postgres)"
description: "Self-hosted n8n queue mode: workers, Redis, Postgres. Zapier alternative."
category: "Automation"
url: https://railway.com/deploy/n8n-workers-queue-mode
---

# Deploy n8n with Workers (Queue Mode + Redis + Postgres)

Self-hosted n8n queue mode: workers, Redis, Postgres. Zapier alternative.

**[Deploy n8n with Workers (Queue Mode + Redis + Postgres) on Railway](https://railway.com/template/n8n-workers-queue-mode)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/n8n-workers-queue-mode/manifest.json

- **Creator:** SilverBanana
- **Category:** Automation

## Template content

### Primary https://devicons.railway.app/i/n8n.svg

- **Image:** n8nio/n8n
- **Start command:** `n8n start`
- **Health check:** /healthz
- **Public domain:** Yes

### Redis https://img.icons8.com/color/48/redis--v1.png

- **Image:** railwayapp/redis

### Postgres https://img.icons8.com/color/48/postgreesql.png

- **Image:** ghcr.io/railwayapp-templates/postgres-ssl:17
- **Start command:** `/bin/sh -c "unset PGPORT; docker-entrypoint.sh postgres --port=5432"`

### Worker https://devicons.railway.app/i/n8n.svg

- **Image:** n8nio/n8n
- **Start command:** `n8n worker`

## Documentation

# Deploy and Host n8n with Workers on Railway

![n8n workflow editor showing a visual automation with connected nodes](https://raw.githubusercontent.com/n8n-io/n8n/master/assets/n8n-screenshot-readme.png)

n8n is the workflow automation platform with **200,000+ GitHub stars**, 400+ integrations and native AI agent nodes. This template deploys n8n on Railway in **queue mode**, so workflow runs are processed by dedicated workers instead of the editor. Zapier charges $129/month for 10,000 tasks — self-host n8n for ~$10–20/month with no execution caps, and keep every workflow, credential and log on infrastructure you control.

---

## What This Template Deploys

| Service | Purpose |
|---|---|
| **Primary** | n8n editor, REST API and webhook receiver (`n8n start`, port 5678, public HTTPS domain, `/healthz` health check). Queues every execution in Redis. |
| **Worker** | n8n worker (`n8n worker`) that pulls jobs from Redis and runs them — up to 10 in parallel by default. Add replicas to scale. |
| **Redis** | Job queue (BullMQ) connecting Primary and Worker over the private network. |
| **Postgres** | PostgreSQL 17 with SSL. Stores workflows, credentials (encrypted) and execution history. |
| **Persistent Volume** | Mounted at `/var/lib/postgresql/data` on Postgres — workflows, credentials and execution history survive redeploys. |
| **Persistent Volume** | Mounted at `/bitnami` on Redis — queued jobs survive restarts. |

All four services are wired together through Railway variable references. Heavy workflows run on workers, so the editor stays responsive.

---

## About Hosting n8n

A single n8n container is fine for testing, but production needs a real database, a queue so long workflows don't block webhooks, scalable workers and one encryption key shared by every process. By hand, that means wiring Postgres, Redis, TLS and a reverse proxy yourself.

On Railway, services talk over a private network, Primary gets an HTTPS domain automatically, Postgres and Redis keep data on volumes, and passwords and the encryption key are generated at deploy time and shared via variable references.

**License note:** n8n is fair-code under the Sustainable Use License, not OSI open source. Self-hosting for your own business or internal use is free; offering n8n itself as a paid hosted service to others is not allowed without a commercial license.

Typical cost: **~$10–20/month** on Railway for light to moderate workloads, with unlimited executions. Zapier Professional is $129/month for 10,000 tasks and n8n Cloud Pro is €50/month for 10,000 executions (both billed annually).

---

## Deploy n8n in Under 5 Minutes

1. Click **Deploy on Railway** — Primary, Worker, Redis and Postgres start together (~2–3 minutes).
2. Leave the generated values as they are — `N8N_ENCRYPTION_KEY` and the database and Redis passwords are created and shared automatically.
3. Open the Primary service's public URL and create your n8n owner account.
4. Build a workflow or import a template, then activate it — executions appear in the queue and run on the Worker.
5. Need more throughput? Increase the Worker service's replicas in Railway.

No SSH. No Docker Compose. No reverse proxy or certificates to manage.

---

## Common Use Cases

- **Self-hosted Zapier alternative** — "zapier alternative self hosted" without per-task pricing
- **High-volume webhook processing** — Primary accepts webhooks while workers handle the load
- **AI agents and LLM pipelines** — run n8n's AI agent nodes against OpenAI, Anthropic or local models
- **Long-running data syncs** — move data between CRMs, databases and sheets without timeouts
- **Internal ops automation** — Slack alerts, ticket routing, scheduled reports
- **Upgrade from single-instance n8n** — switch to queue mode when one container can't keep up

---

## Configuration

| Variable | Required | Description |
|---|---|---|
| `N8N_ENCRYPTION_KEY` | 🔐 Auto-generated | Encrypts stored credentials. Generated on Primary; Worker references the same value. **Never change it after saving credentials.** |
| `N8N_WEBHOOK_URL` | ✅ Auto-injected | Public base URL for webhooks. Defaults to Primary's Railway domain. |
| `N8N_EDITOR_BASE_URL` | ✅ Auto-injected | Public URL of the editor. Defaults to Primary's Railway domain. |
| `EXECUTIONS_MODE` | ✅ Set to `queue` | Sends executions to Redis for workers. Must be `queue` on Primary and Worker. |
| `OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS` | Optional | `true` — editor test runs also execute on workers. |
| `DB_POSTGRESDB_*` | ✅ Auto-injected | Host, port, database, user and password from the Postgres service. |
| `QUEUE_BULL_REDIS_*` | ✅ Auto-injected | Host, port, user and password from the Redis service. |
| `NODE_OPTIONS` | Optional | `--max_old_space_size=8192` — Node.js heap ceiling, not a memory reservation. |
| `PORT` | Auto-set | `5678` on Primary and Worker. |

**Using a custom domain?** Update `N8N_WEBHOOK_URL` and `N8N_EDITOR_BASE_URL` on Primary (and `N8N_WEBHOOK_URL` on Worker) to your domain. Otherwise webhook nodes keep showing the `*.up.railway.app` address and external services call the wrong URL.

---

## n8n vs. Alternatives

| | n8n (Railway) | Zapier | n8n Cloud | Activepieces |
|---|---|---|---|---|
| **Monthly cost** | ~$10–20 usage | $129 for 10K tasks | €50 for 10K executions | Free self-hosted |
| **Self-hosted** | ✅ Yes | ❌ No | ❌ No | ✅ Yes |
| **Execution limits** | ✅ None (your resources) | ❌ Per task | ❌ Per plan | ✅ None |
| **Scale with worker replicas** | ✅ Yes | — Managed | — Managed | ⚠️ Self-managed |
| **Data stays on your infra** | ✅ Yes | ❌ No | ❌ No | ✅ Yes |
| **Visual editor + custom code** | ✅ JS & Python | ✅ | ✅ JS & Python | ✅ TypeScript |
| **License** | ⚠️ Fair-code (Sustainable Use) | ❌ Proprietary | ⚠️ Fair-code | ✅ MIT (Community) |

---

## Dependencies for n8n Hosting

- Railway account — Hobby ($5/month) for light use, Pro ($20/month) for production. ~0.7–1 GB RAM total at idle.
- Credentials for the apps you automate (API keys, OAuth apps) — added inside n8n.
- A modern browser for the n8n editor.

### Deployment Dependencies

- [n8n GitHub](https://github.com/n8n-io/n8n) — source and releases
- [n8n Documentation](https://docs.n8n.io/) — setup and node reference
- [n8n Queue Mode](https://docs.n8n.io/hosting/scaling/queue-mode/) — how workers, Redis and Postgres fit together
- [Railway Volumes Documentation](https://docs.railway.com/volumes) — persistence

### Implementation Details

The template runs the official `n8nio/n8n` image twice — as **Primary** (`n8n start`) and **Worker** (`n8n worker`) — alongside `railwayapp/redis` and `ghcr.io/railwayapp-templates/postgres-ssl:17`. Primary receives editor traffic and webhooks and pushes execution IDs to Redis; workers pick them up, load the workflow from Postgres, run it and write the results back. Postgres data lives on a volume at `/var/lib/postgresql/data` and Redis data at `/bitnami`.

The setting that matters most is `N8N_ENCRYPTION_KEY`: Worker references Primary's key so both can decrypt the same credentials — keep it unchanged. To reach Postgres or Redis from another service, reference their variables (e.g. `${{Postgres.PGHOST}}`) instead of hard-coding hosts.

---

## Frequently Asked Questions

**What is n8n queue mode, and why use workers?**
The main instance handles the editor, triggers and webhooks and hands each execution to a Redis queue; worker processes run the workflows. Heavy workflows stop slowing the editor or delaying webhooks, and you add workers as volume grows.

**How much does self-hosting n8n on Railway cost compared to Zapier?**
Expect roughly $10–20/month in Railway usage for light to moderate workloads, with no limit on executions. Zapier Professional costs $129/month for 10,000 tasks (billed annually), and n8n Cloud Pro costs €50/month for 10,000 executions.

**Why is my n8n webhook URL wrong or not working?**
n8n builds webhook URLs from `N8N_WEBHOOK_URL`. This template sets it to Primary's Railway domain. If you add a custom domain, update `N8N_WEBHOOK_URL` and `N8N_EDITOR_BASE_URL` to that domain and redeploy, then re-copy the webhook URL into the external service.

**Do I lose my workflows or credentials when I redeploy?**
No. Workflows, credentials and execution history are stored in Postgres on a persistent volume, and the Redis queue is on its own volume. Redeploying or updating n8n keeps them, as long as `N8N_ENCRYPTION_KEY` stays the same.

**How do I scale n8n workers?**
Increase the replica count on the Worker service in Railway. Each worker runs up to 10 executions in parallel by default, and all replicas share the same Redis queue and Postgres database.

**Is n8n free to self-host for commercial use?**
Yes, for internal business use. n8n's Sustainable Use License lets you automate your own company's work for free. Reselling n8n itself as a hosted service, or embedding it in a product for customers, needs a commercial license from n8n.

---

## Why Deploy and Host n8n with Workers on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying n8n with workers on Railway, you get production-ready queue-mode automation — editor, scalable workers, Redis and Postgres — with unlimited executions for a fraction of what Zapier or n8n Cloud charge, and full ownership of your data.


## Similar templates

- [N8N Main + Worker](https://railway.com/deploy/n8n-main-worker) — Deploy and Host N8N with Inactive worker.
- [Evolution API with n8n](https://railway.com/deploy/evolution-api-with-n8n) — Automate WhatsApp workflows with Evolution API, n8n, and Postgres.
- [Postgres Backup](https://railway.com/deploy/postgres-s3-backups) — Cron-based PostgreSQL backup to bucket storage

Open this page in a browser: https://railway.com/deploy/n8n-workers-queue-mode
