n8n w/ worker, external pgsql

Deploy and Host n8n w/ worker, external pgsql with Railway

Deploy n8n w/ worker, external pgsql

n8n-main

n8nio/n8n:latest

Just deployed

n8n-worker

n8nio/n8n:latest

Just deployed

Redis

bitnami/redis:7.2.5

Just deployed

/bitnami

Deploy and Host n8n w/ worker and external pgsql on Railway

n8n is an open-source workflow automation platform. This template sets up a production-ready architecture with a primary n8n instance (handling the UI and triggers), a worker instance for background job processing, Redis for task queueing, and an external PostgreSQL database for persistent storage — all deployed on Railway.

About Hosting n8n w/ worker and external pgsql

This deployment separates the responsibilities of the n8n application to ensure better performance, fault tolerance, and scalability. The n8n-main service handles incoming triggers and user interactions via the UI, while the n8n-worker processes jobs asynchronously through a Redis queue. The external PostgreSQL database stores workflow definitions, credentials, execution logs, and more, decoupling state from the runtime. This architecture mirrors the recommended setup for production environments and gives you complete control of how you scale each component.

Common Use Cases

  • Automating workflows between APIs, databases, and services (e.g., CRMs, email, Slack)
  • Running large-scale automations with job workers offloaded from the main service
  • Centralized automation backend for internal tools or no-code platforms

Dependencies for n8n w/ worker and external pgsql Hosting

  • Redis (for distributed job queues)
  • External PostgreSQL (for persistence across restarts and scaling)

Deployment Dependencies

  • A hosted PostgreSQL instance (Railway PostgreSQL plugin or self-hosted)
  • Optionally, a domain and HTTPS proxy (e.g., Cloudflare or Railway’s custom domain support)

Implementation Details

services:
  n8n-main:
    image: n8nio/n8n:latest
    ports:
      - "5678:5678"
    environment:
      - EXECUTIONS_MODE=queue
      - QUEUE_MODE=redis
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=${DB_HOST}
      - DB_POSTGRESDB_PORT=${DB_PORT}
      - DB_POSTGRESDB_DATABASE=${DB_NAME}
      - DB_POSTGRESDB_USER=${DB_USER}
      - DB_POSTGRESDB_PASSWORD=${DB_PASSWORD}
      - REDIS_HOST=redis
      - REDIS_PORT=6379

  n8n-worker:
    image: n8nio/n8n:latest
    environment:
      - EXECUTIONS_MODE=queue
      - QUEUE_MODE=redis
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=${DB_HOST}
      - DB_POSTGRESDB_PORT=${DB_PORT}
      - DB_POSTGRESDB_DATABASE=${DB_NAME}
      - DB_POSTGRESDB_USER=${DB_USER}
      - DB_POSTGRESDB_PASSWORD=${DB_PASSWORD}
      - REDIS_HOST=redis
      - REDIS_PORT=6379

  redis:
    image: redis:6
    ports:
      - "6379:6379"

Why Deploy n8n w/ worker and external pgsql 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 w/ worker and external pgsql on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.


Template Content

More templates in this category

View Template
Foundry Virtual Tabletop
A Self-Hosted & Modern Roleplaying Platform

View Template
(v1) Simple Medusa Backend
Deploy an ecommerce backend and admin using Medusa

View Template
peppermint
Docker-compose port for peppermint.sh