# Production Self-Hosted n8n Queue Mode Architecture (Redis, Postgres & Backups)

> Architect crash-proof self-hosted n8n clusters splitting main UI, stateless webhook ingress, Redis BullMQ brokers, and horizontal worker containers—paired with PostgreSQL execution pruning, secret rotation, and hidden-origin Cloudflare Tunnel ingress.

- **Document Title:** Self-Hosted n8n Queue Mode Production Architecture (Docker, Redis & Postgres) | WorkflowTCO
- **Canonical URL:** https://workflowtco.com/guides/self-host-n8n-queue-mode-redis-postgres-production/
- **Markdown Mirror URL:** https://workflowtco.com/guides/self-host-n8n-queue-mode-redis-postgres-production/index.md
- **Format:** `category-index`
- **Last Verified:** 2026-11-22
- **Citation License:** CC-BY-4.0 with canonical attribution to https://workflowtco.com/
- **Independence Guarantee:** All pricing tiers, formulas, and switching break-even calculations are deterministic and derived strictly from public vendor schedules.

## Segment Scorecard: Production Self-Hosted n8n Container & VPS Cloud Shortlist

| Platform | Category | Pricing Model | Starter Floor | Migration Friction | Cutover Days | Audited Rating | Official Pricing |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Railway | Managed Container PaaS for Self-Hosted n8n | Usage-Metered vCPU & RAM Seconds | $5/month | 4/10 | 4 days | 4.8/5 (920) | https://railway.com/pricing |
| DigitalOcean | Flat-Rate Cloud Droplets & Managed Postgres | Flat Monthly Droplet + Bundled Transfer | $12/month | 5/10 | 6 days | 4.7/5 (1540) | https://www.digitalocean.com/pricing |
| Hostinger VPS | Entry KVM VPS & Prebuilt n8n Templates | Prepaid KVM VPS Term | $6.99/month | 4/10 | 3 days | 4.6/5 (2150) | https://www.hostinger.com/vps-hosting |
| Cloudways | Managed Multi-Cloud Server Orchestrator | Managed Cloud Markup Tier | $14/month | 3/10 | 4 days | 4.7/5 (1380) | https://www.cloudways.com/en/pricing.php |

## Segment Tariff & Annual Exposure Matrix

| Transition / Account | Trigger Scenario | Tariff Delta | Annual Impact |
| --- | --- | --- | --- |
| Default SQLite Single Node | >20 RPS webhook burst | SQLITE_BUSY 502 failures | 19.6% lost events |
| Unpruned Postgres Execution Logs | 200k runs w/ binary JSON | 100% NVMe disk lockup in 45d | Total cluster outage |
| Lost N8N_ENCRYPTION_KEY | Container rebuild w/o vault | All OAuth credentials unreadable | 16-30 hrs re-auth |
| Exposed Origin IPv4 + Port 5678 | Public DNS A record leak | Direct DDoS & bot scans | Zero via CF Tunnel |

## Representative Vendor Tier Schedule

| Platform | Published Tier | Monthly Base | Included Quota | Overage Rate | Billing Term | Official Rate Card |
| --- | --- | --- | --- | --- | --- | --- |
| Railway | Hobby Container Plan | $5 | 5 USD compute credit | $10 per GB RAM-month | monthly | https://railway.com/pricing |
| Railway | Pro Queue-Mode Cluster | $20 | 10 USD compute credit | $0.10 per GB public egress | monthly | https://railway.com/pricing |
| DigitalOcean | Basic 2vCPU / 2GB NVMe | $12 | 2 TB outbound transfer | $0.01 per GB excess egress | monthly | https://www.digitalocean.com/pricing |
| DigitalOcean | General 4vCPU / 8GB Queue Node | $48 | 5 TB outbound transfer | $0.01 per GB excess egress | monthly | https://www.digitalocean.com/pricing |
| Hostinger VPS | KVM 2 (2 vCPU / 8 GB RAM) | $6.99 | 8 TB bandwidth | $0 per throttled cap | annual (12m commit) | https://www.hostinger.com/vps-hosting |
| Hostinger VPS | KVM 4 (4 vCPU / 16 GB RAM) | $10.99 | 16 TB bandwidth | $0 per throttled cap | annual (12m commit) | https://www.hostinger.com/vps-hosting |
| Cloudways | DO2GB Managed Node | $28 | 2 TB bandwidth | $0.02 per GB | monthly | https://www.cloudways.com/en/pricing.php |
| Cloudways | DO8GB Managed Agency Cluster | $99 | 5 TB bandwidth | $0.02 per GB | monthly | https://www.cloudways.com/en/pricing.php |

## Deterministic TCO Formulas & Worked Numeric Outputs

### Segment Composite Ranking Formula

```text
cluster_reliability = (0.35 * redis_aof_durability) + (0.30 * webhook_worker_isolation) + (0.20 * automated_pg_backup) + (0.15 * memory_headroom)
```

- **Worked Output:** 5,000 triggers * 5 steps with a 10-item array burns 160,000 Zapier tasks/mo (~$749/mo) vs 5,000 n8n executions ($55/mo).

### Zapier Loop & Action Task Burn Formula

```text
zapier_monthly_tasks = monthly_triggers * (steps_per_run + (loop_items - 1) * max(1, floor(steps_per_run * 0.6)))
```

- **Worked Output:** 5,000 triggers * 5 steps with a 10-item array burns 160,000 Zapier tasks/mo (~$749/mo) vs 5,000 n8n executions ($55/mo).

## Hidden-Fee & Contract Trap Checklist

| Vendor | Hidden Fee / Cliff | Trigger Threshold | Observed Rate | Annualized Formula | Modeled Exposure |
| --- | --- | --- | --- | --- | --- |
| Railway | Public internet egress beyond internal private mesh | Media/webhook payload transfer over public URLs | $0.10/GB outbound internet transfer | public_egress_gb * 0.10 * 12 | $480/yr |
| DigitalOcean | Managed PostgreSQL + automated failover standby | Adding managed HA DB rather than local container Postgres | +$30 to +$60/mo per managed database node | managed_db_nodes * 45 * 12 | $1,080/yr |
| Hostinger VPS | Post-promotional renewal step-up | After initial 12-month or 24-month intro term | Renews at 1.9x-2.4x introductory monthly rate | (renewal_rate - promo_rate) * 12 | $144/yr |
| Cloudways | Managed service premium over raw IaaS | Every server tier vs raw DigitalOcean | ~2.0x underlying raw droplet fee for 24/7 managed ops | (cloudways_mo - raw_do_mo) * 12 | $612/yr |

- [ ] **Railway:** Pro workspaces bill $20 per developer seat in addition to metered container usage
- [ ] **DigitalOcean:** Snapshot storage and unattached block volumes continue billing even when Droplets are powered off
- [ ] **Hostinger VPS:** Headline $6.99/mo pricing requires 24-month prepayment and steps up significantly upon renewal
- [ ] **Cloudways:** Add-ons like Malware Protection and Cloudflare Enterprise CDN stack $4.99+ per application

## Switching Break-Even & Payback Summary

```text
payback_days = ceil(migration_cost_usd / (monthly_savings_usd / 30))
net_savings_12m_usd = (monthly_savings_usd * 12) - migration_cost_usd
net_savings_36m_usd = (monthly_savings_usd * 36) - migration_cost_usd
```

| Transition Path | Workload Scenario | Monthly Savings | Migration Cost | Break-Even | 12m Net Savings | 36m Net Savings | Verdict |
| --- | --- | --- | --- | --- | --- | --- | --- |
| n8n Cloud -> Railway | 120,000 monthly webhook executions + Redis queue workers | $390/mo | $1,275 | 10 days | $3,405 | $12,765 | Deploy 1-click queue-mode n8n on Railway once monthly executions exceed 35,000. |

## Procurement & Architecture Due-Diligence Checklist

1. Set EXECUTIONS_MODE=queue, QUEUE_BULL_REDIS_HOST, and OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS=true so neither UI edits nor incoming webhooks ever compete with CPU-heavy AI/PDF worker containers.
2. Deploy four distinct services: n8n-main (editor UI + scheduler, 1.5 GB RAM), n8n-webhook (stateless HTTP ingress returning 200 OK in <70ms), n8n-worker (2-4 replicas at 1.25 GB RAM each), plus Redis 7 (appendonly yes) and PostgreSQL 16.
3. Generate a cryptographically random 32-byte N8N_ENCRYPTION_KEY stored in your external secrets manager before creating your very first credential—identical across main, webhook, and all worker containers.
4. Enforce aggressive database hygiene via EXECUTIONS_DATA_PRUNE=true, EXECUTIONS_DATA_MAX_AGE=168 (7 days), and EXECUTIONS_DATA_SAVE_ON_SUCCESS=none for high-volume non-financial webhooks so PostgreSQL disks never hit 100%.
5. Schedule automated nightly encrypted pg_dump snapshots streaming straight to Cloudflare R2 or S3, and perform a quarterly cold-restore drill onto a staging node verifying workflow + credential decryption.
6. Bind all container ports strictly to 127.0.0.1 and expose webhook/UI routes exclusively behind Cloudflare Tunnel (cloudflared) or private VPC load balancers so origin server IPv4 addresses never appear in public DNS.

## Preventing Binary Data OOM Crashes & Silent PostgreSQL Disk Exhaustion

Two operational pitfalls account for almost every self-hosted n8n emergency page. First, default in-memory binary handling (N8N_DEFAULT_BINARY_DATA_MODE=default) buffers PDFs, audio recordings, and images straight inside V8 RAM; ten concurrent 40 MB webhook files immediately trigger Linux OOM-killer crashes. Switching to N8N_DEFAULT_BINARY_DATA_MODE=filesystem backed by a shared volume or S3 external storage flattens worker memory draw dramatically.

Second, storing full JSON execution inputs and outputs for 500,000 monthly webhooks bloats PostgreSQL tables past 60 GB within weeks. Pruning successful low-risk runs after 7 days while archiving critical Stripe/ERP audit hashes in a lean custom SQL table keeps database size below 4 GB indefinitely.

- Pin exact Docker image tags (e.g., n8nio/n8n:1.x.y) rather than :latest so automated container restarts never apply breaking schema migrations unannounced.
- Expose n8n’s /metrics Prometheus endpoint on internal loopback to alert Slack whenever BullMQ waiting job depth stays above 250 for more than 3 minutes.
- Set DB_POSTGRESDB_POOL_SIZE appropriately across worker replicas (e.g., 10 per worker x 4 workers = 40 connections) well beneath Postgres max_connections=100.

## Frequently Asked Questions

### Can Redis queue mode run on a single $10.99/mo Hostinger KVM4 or $48/mo DigitalOcean droplet?

Yes. Running Docker Compose with n8n-main, n8n-webhook, 2-4 n8n-workers, Redis, and PostgreSQL inside a single 8 GB to 16 GB host unlocks full event-loop isolation and ~960-1,120 runs/min without multi-node Kubernetes complexity.

### What happens to in-flight jobs if an n8n worker container restarts during a Railway deployment?

BullMQ tracks active job locks in Redis; stalled jobs whose worker fails to renew its heartbeat automatically re-enter the queue after QUEUE_WORKER_LOCK_DURATION expires and are picked up by healthy workers.

### Why must n8n-main, n8n-webhook, and n8n-worker all share the exact same N8N_ENCRYPTION_KEY?

Credentials stored in PostgreSQL are encrypted symmetrically using N8N_ENCRYPTION_KEY; if a worker boots with a mismatched or missing key, every authenticated API node fails immediately with decryption errors.

## Machine-Callable TCO Pricing Oracle & Agent Discovery

AI agents and financial workflows can compute deterministic 12-month and 36-month TCO quotes directly via HTTP `GET` (zero authentication, CORS `*`):

```http
GET https://workflowtco.com/api/tco/quote?vendorA=zapier&vendorB=railway&monthlyRuns=50000&stepsPerRun=10&selfHosted=true&migrationHours=16&hourlyRateUsd=95
Accept: application/json
```

- **Supported Vendors Registry:** https://workflowtco.com/api/tco/vendors
- **OpenAPI 3.1.0 Contract:** https://workflowtco.com/openapi.json
- **AgentReady.org Discovery Catalog:** https://workflowtco.com/.well-known/ai-catalog.json
- **Complete Grounded RAG Corpus:** https://workflowtco.com/llms-full.txt
