Railway

Deploy n8n — Self-Hosted Workflow Automation

Self-host n8n — 400+ integrations, Postgres & AI workflows, no caps

Deploy n8n — Self-Hosted Workflow Automation

Just deployed

Deploy and Host n8n on Railway

Self-host the open-source alternative to Zapier — unlimited executions, no per-task billing, and full ownership of your data. n8n is the world's most popular workflow automation platform (188k+ GitHub stars, 100M+ Docker pulls, 500+ integrations). Build automations visually, drop into code when you need it, and wire up AI agents, APIs, and databases — with no execution caps and no vendor lock-in. This template runs n8n with a managed PostgreSQL database, pre-wired so workflows and credentials persist from the first deploy.

n8n workflow builder


What This Template Deploys

ServicePurpose
n8nThe workflow engine and visual editor at your Railway URL on port 5678
PostgreSQLManaged Railway database — stores workflows, credentials, and execution history persistently

Both services connect over Railway's private network, with PostgreSQL credentials injected automatically. Storing state in Postgres rather than inside the container is what keeps your workflows safe across redeploys.


About Hosting

n8n is quick to deploy, but two settings make the difference between a working instance and a frustrating one — and this template handles both.

WEBHOOK_URL must be your Railway public domain. Webhook-triggered workflows only receive external traffic if n8n knows its own public URL. Set WEBHOOK_URL to your Railway domain (found under the n8n service → Settings → Domains), or triggers from Stripe, GitHub, Shopify, and other services silently won't fire. It's the number-one "my webhooks don't work" issue.

N8N_ENCRYPTION_KEY protects your stored credentials — pin it and keep it stable. n8n encrypts every saved credential (API keys, OAuth tokens, database logins) with this key. If it changes or is regenerated on a redeploy, existing credentials can't be decrypted and you'll see "Credentials could not be decrypted." Set a 32-character random value once, keep it stable, and back it up.

Everything persists in PostgreSQL, not the container. Workflows, credentials, and execution history live in the Railway-managed database, so redeploys, updates, and restarts never touch them — the reason this template uses Postgres rather than SQLite-in-a-volume.

Secure the editor. On a public URL, enable basic auth (N8N_BASIC_AUTH_ACTIVE=true with a user and strong password) so your workflow editor isn't openly reachable. Railway's automatic HTTPS handles encryption in transit.

Pin the version in production. Set a specific image tag (e.g. n8nio/n8n:2.20.9) rather than latest, so an upstream release doesn't introduce breaking changes under you. Upgrades are a tag change and a redeploy; your Postgres data is unaffected.

Typical cost: ~$5/month on Railway's Hobby plan — with unlimited executions, versus n8n Cloud's $20/month (capped at 2,500) or Zapier's per-task billing.


How It Compares

n8n (self-hosted)n8n CloudZapierMake
Monthly cost~$5 (Railway)From $20From $19.99From $9
ExecutionsUnlimited2,500–10,000 capPer stepPer operation
Data ownershipYour infran8n serversZapier serversMake servers
Custom codeJS/Python + npmYesLimitedLimited
AI/LLM nodesNativeYesBasicBasic
Self-hostableYesNoNoNo

Zapier and Make bill per task or operation, so a 10-step workflow multiplies fast, and both keep your data on their servers. n8n Cloud caps executions. Self-hosted n8n on Railway gives you unlimited executions, native AI and code nodes, and full data ownership at flat cost — the reason it's the go-to for anyone automating at volume.


Deploy in Under 5 Minutes

  1. Click Deploy on Railway — n8n and PostgreSQL provision automatically (~2–3 minutes)
  2. Set WEBHOOK_URL to your Railway public domain and pin N8N_ENCRYPTION_KEY
  3. Enable basic auth with a username and strong password
  4. Open your Railway URL and set your admin credentials on first launch
  5. Start building workflows immediately

No SSH, no Docker Compose, no reverse proxy, no SSL certificates to manage.


Common Use Cases

  • Zapier alternative without per-task billing — a 10-step workflow is one execution here, not ten billed tasks
  • AI and LLM orchestration — connect Claude, GPT-4o, or Gemini to APIs, databases, and logic with native AI and LangChain nodes
  • Business process automation — CRM updates, support routing, invoice processing, and cross-tool sync without execution caps
  • Scheduled background jobs — cron-based reports, monitoring, backups, and recurring tasks at any frequency

Configuration

VariableRequiredDescription
WEBHOOK_URLRequiredYour Railway public URL — required for webhook triggers to work
N8N_ENCRYPTION_KEYRecommended32-character random string — encrypts stored credentials; keep it stable
DB_TYPEPre-setpostgresdb — connects n8n to Railway PostgreSQL
DB_POSTGRESDB_HOSTAuto-injectedPostgreSQL private hostname via Railway reference variable
DB_POSTGRESDB_DATABASEAuto-injectedDatabase name from the Railway PostgreSQL service
DB_POSTGRESDB_USERAuto-injectedDatabase user from the Railway PostgreSQL service
DB_POSTGRESDB_PASSWORDAuto-injectedDatabase password via Railway secret reference
N8N_BASIC_AUTH_ACTIVERecommendedtrue — protects the editor from public access
N8N_BASIC_AUTH_USER / _PASSWORDRecommendedBasic-auth credentials — use a strong password
PORTPre-set5678 — the default n8n port

Set WEBHOOK_URL to your Railway domain. Find it under the n8n service → Settings → Domains. Without it, webhook-triggered workflows won't receive external traffic — the most common setup issue.

Keep N8N_ENCRYPTION_KEY stable. It encrypts stored credentials; changing it causes "Credentials could not be decrypted." Set it once and back it up.


Dependencies for n8n Hosting

  • Railway account — ~$5/month on the Hobby plan with unlimited executions
  • PostgreSQL (included and auto-wired in this template)
  • Your own API keys for any AI models or third-party services you connect
  • A Railway public domain for webhook triggers

Deployment Dependencies

Implementation Details

The template runs the official n8n image on port 5678 alongside a Railway-managed PostgreSQL service (postgres-ssl:17), connected over the private network with database credentials injected through reference variables. n8n stores all workflows, credentials, and execution history in PostgreSQL rather than the container filesystem, so state survives redeploys, updates, and restarts.

WEBHOOK_URL must match the deployment's public domain for webhook-triggered workflows to receive external events, and N8N_ENCRYPTION_KEY encrypts stored credentials — it must remain stable across redeploys or saved credentials become undecryptable. Basic auth guards the editor on a public URL, and Railway provides automatic HTTPS. Upgrading n8n is a matter of changing the image tag and redeploying, with the PostgreSQL data unaffected; pinning a specific version rather than latest is recommended for production stability.

The Community Edition self-hosted here includes all 500+ integrations, native AI and LangChain nodes, and custom JavaScript/Python with npm — the full workflow feature set, without execution caps.


Frequently Asked Questions

How much does it cost to run n8n on Railway? Around $5/month on the Hobby plan, with unlimited executions. n8n Cloud Starter is $20/month capped at 2,500 executions; Zapier Starter is $19.99/month for 750 tasks where every workflow step counts separately.

Do I lose my workflows if Railway redeploys? No. Everything is stored in the Railway-managed PostgreSQL database, not inside the container, so redeploys, updates, and restarts don't touch your workflows, credentials, or history.

Do webhooks work on Railway? Yes. Set WEBHOOK_URL to your Railway public domain and external services can trigger your workflows in real time, with automatic HTTPS and no certificate setup.

Can I use n8n's AI and LangChain nodes when self-hosting? Yes — all of them. Claude, GPT-4o, Gemini, Pinecone, Qdrant, and vector-store integrations are included in the free Community Edition. Bring your own API keys, with no AI execution limits.

What does Community Edition not include vs n8n Cloud? Only enterprise extras: SSO/SAML, advanced RBAC, audit-log streaming, and support SLAs. All 500+ integrations, AI nodes, and core workflow features are fully available self-hosted.

How do I update n8n? Change the Docker image tag in Railway settings (e.g. n8nio/n8n:2.20.9) and redeploy. Your PostgreSQL data is unaffected. Pin a specific version in production rather than latest.

Why is my credential showing "could not be decrypted"? The N8N_ENCRYPTION_KEY changed. It must stay stable across redeploys — set it once, keep it, and back it up.


Why Deploy n8n 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 on Railway you get unlimited workflow executions, a production-grade PostgreSQL backend, automatic HTTPS webhook support, and zero server administration — at ~$5/month flat, with full ownership of your data and automations.


Template Content

More templates in this category

View Template
N8N Main + Worker
Deploy and Host N8N with Inactive worker.

jakemerson
120
View Template
Evolution API with n8n
[Jul'26] WhatsApp automation platform using Evolution API, n8n & PostgreSQL

codestorm
60
View Template
Postgres Backup
Cron-based PostgreSQL backup to bucket storage

Railway Templates
869