n8n + PostgreSQL + Redis
Workflow automation platform with 300+ integrations.
Overview
n8n (pronounced n-eight-n) is a fair-code workflow automation platform that serves as a powerful self-hosted alternative to services like Zapier and Microsoft Power Automate. Founded in 2019, n8n provides a visual workflow builder with over 350 pre-built integrations, allowing users to connect different services and automate complex business processes without writing code. Unlike SaaS alternatives, n8n's fair-code licensing model ensures the source code remains accessible while providing enterprise features for commercial use.
This production-ready stack combines n8n with PostgreSQL for robust data persistence and Redis for high-performance queue management. PostgreSQL stores workflow definitions, execution history, and user credentials with ACID compliance, while Redis handles the execution queue system that enables horizontal scaling through worker processes. The configuration includes a separate n8n-worker container that processes workflows asynchronously, preventing the main application from becoming overwhelmed during high-volume automation runs.
This stack is ideal for organizations requiring scalable workflow automation with enterprise-grade reliability. Small to medium businesses benefit from the cost savings compared to per-execution SaaS pricing, while larger enterprises appreciate the data sovereignty and customization options. DevOps teams favor this setup for CI/CD integrations, IT departments use it for system monitoring and alerting workflows, and marketing teams leverage it for lead nurturing and customer communication automation.
Key Features
- Visual workflow editor with 350+ pre-built service integrations including Slack, Google Workspace, AWS, and Salesforce
- Queue-based execution system using Redis Bull queues for horizontal scaling and reliable workflow processing
- PostgreSQL database backend providing ACID compliance for workflow definitions, execution history, and credential storage
- Dedicated worker processes for handling long-running workflows without blocking the main application interface
- Webhook triggers supporting real-time workflow initiation from external services and custom applications
- Advanced error handling with configurable retry policies, exponential backoff, and workflow branching based on success/failure
- Credential management system with AES encryption for securely storing API keys and authentication tokens
- Execution history with detailed logs, performance metrics, and workflow debugging capabilities
Common Use Cases
- 1E-commerce order processing automation connecting Shopify, inventory systems, shipping providers, and customer communication tools
- 2Lead nurturing workflows that sync CRM data, trigger email sequences, and update marketing automation platforms based on user behavior
- 3IT monitoring and incident response automating Prometheus alerts, creating Jira tickets, and notifying teams via Slack or PagerDuty
- 4Data synchronization between business systems like syncing customer data from Salesforce to marketing tools and accounting software
- 5Social media management workflows that cross-post content, monitor mentions, and aggregate analytics across multiple platforms
- 6DevOps CI/CD pipeline integration triggering deployments, running tests, and sending notifications based on Git repository changes
- 7Customer support automation routing tickets, escalating issues, and updating knowledge bases based on common inquiries
Prerequisites
- Minimum 1GB RAM (2GB+ recommended) to support n8n application, PostgreSQL database, and Redis queue processing
- Port 5678 available for n8n web interface access and API endpoints
- Basic understanding of workflow automation concepts and API integrations for creating effective n8n workflows
- Knowledge of environment variable configuration for setting up database connections and authentication credentials
- Familiarity with Docker networking concepts for troubleshooting inter-container communication issues
- Understanding of backup strategies for PostgreSQL data and n8n workflow configurations
For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms
docker-compose.yml
docker-compose.yml
1services: 2 n8n: 3 image: n8nio/n8n:latest4 environment: 5 - N8N_BASIC_AUTH_ACTIVE=true6 - N8N_BASIC_AUTH_USER=${N8N_USER}7 - N8N_BASIC_AUTH_PASSWORD=${N8N_PASSWORD}8 - DB_TYPE=postgresdb9 - DB_POSTGRESDB_HOST=postgres10 - DB_POSTGRESDB_PORT=543211 - DB_POSTGRESDB_DATABASE=n8n12 - DB_POSTGRESDB_USER=${POSTGRES_USER}13 - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}14 - EXECUTIONS_MODE=queue15 - QUEUE_BULL_REDIS_HOST=redis16 - N8N_ENCRYPTION_KEY=${ENCRYPTION_KEY}17 volumes: 18 - n8n-data:/home/node/.n8n19 ports: 20 - "5678:5678"21 depends_on: 22 - postgres23 - redis24 networks: 25 - n8n-network26 restart: unless-stopped2728 n8n-worker: 29 image: n8nio/n8n:latest30 command: worker31 environment: 32 - DB_TYPE=postgresdb33 - DB_POSTGRESDB_HOST=postgres34 - DB_POSTGRESDB_PORT=543235 - DB_POSTGRESDB_DATABASE=n8n36 - DB_POSTGRESDB_USER=${POSTGRES_USER}37 - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}38 - EXECUTIONS_MODE=queue39 - QUEUE_BULL_REDIS_HOST=redis40 - N8N_ENCRYPTION_KEY=${ENCRYPTION_KEY}41 depends_on: 42 - n8n43 - postgres44 - redis45 networks: 46 - n8n-network47 restart: unless-stopped4849 postgres: 50 image: postgres:1551 environment: 52 - POSTGRES_USER=${POSTGRES_USER}53 - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}54 - POSTGRES_DB=n8n55 volumes: 56 - postgres-data:/var/lib/postgresql/data57 networks: 58 - n8n-network59 restart: unless-stopped6061 redis: 62 image: redis:alpine63 volumes: 64 - redis-data:/data65 networks: 66 - n8n-network67 restart: unless-stopped6869volumes: 70 n8n-data: 71 postgres-data: 72 redis-data: 7374networks: 75 n8n-network: 76 driver: bridge.env Template
.env
1# n8n Automation2N8N_USER=admin3N8N_PASSWORD=secure_admin_password4POSTGRES_USER=n8n5POSTGRES_PASSWORD=secure_postgres_password6ENCRYPTION_KEY=your-encryption-key78# Generate key: openssl rand -hex 32Usage Notes
- 1Web UI at http://localhost:5678
- 2300+ integrations available
- 3Visual workflow editor
- 4Queue mode for scaling
- 5Self-hosted Zapier alternative
Individual Services(4 services)
Copy individual services to mix and match with your existing compose files.
n8n
n8n:
image: n8nio/n8n:latest
environment:
- N8N_BASIC_AUTH_ACTIVE=true
- N8N_BASIC_AUTH_USER=${N8N_USER}
- N8N_BASIC_AUTH_PASSWORD=${N8N_PASSWORD}
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_PORT=5432
- DB_POSTGRESDB_DATABASE=n8n
- DB_POSTGRESDB_USER=${POSTGRES_USER}
- DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
- EXECUTIONS_MODE=queue
- QUEUE_BULL_REDIS_HOST=redis
- N8N_ENCRYPTION_KEY=${ENCRYPTION_KEY}
volumes:
- n8n-data:/home/node/.n8n
ports:
- "5678:5678"
depends_on:
- postgres
- redis
networks:
- n8n-network
restart: unless-stopped
n8n-worker
n8n-worker:
image: n8nio/n8n:latest
command: worker
environment:
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_PORT=5432
- DB_POSTGRESDB_DATABASE=n8n
- DB_POSTGRESDB_USER=${POSTGRES_USER}
- DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
- EXECUTIONS_MODE=queue
- QUEUE_BULL_REDIS_HOST=redis
- N8N_ENCRYPTION_KEY=${ENCRYPTION_KEY}
depends_on:
- n8n
- postgres
- redis
networks:
- n8n-network
restart: unless-stopped
postgres
postgres:
image: postgres:15
environment:
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=n8n
volumes:
- postgres-data:/var/lib/postgresql/data
networks:
- n8n-network
restart: unless-stopped
redis
redis:
image: redis:alpine
volumes:
- redis-data:/data
networks:
- n8n-network
restart: unless-stopped
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 n8n:5 image: n8nio/n8n:latest6 environment:7 - N8N_BASIC_AUTH_ACTIVE=true8 - N8N_BASIC_AUTH_USER=${N8N_USER}9 - N8N_BASIC_AUTH_PASSWORD=${N8N_PASSWORD}10 - DB_TYPE=postgresdb11 - DB_POSTGRESDB_HOST=postgres12 - DB_POSTGRESDB_PORT=543213 - DB_POSTGRESDB_DATABASE=n8n14 - DB_POSTGRESDB_USER=${POSTGRES_USER}15 - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}16 - EXECUTIONS_MODE=queue17 - QUEUE_BULL_REDIS_HOST=redis18 - N8N_ENCRYPTION_KEY=${ENCRYPTION_KEY}19 volumes:20 - n8n-data:/home/node/.n8n21 ports:22 - "5678:5678"23 depends_on:24 - postgres25 - redis26 networks:27 - n8n-network28 restart: unless-stopped2930 n8n-worker:31 image: n8nio/n8n:latest32 command: worker33 environment:34 - DB_TYPE=postgresdb35 - DB_POSTGRESDB_HOST=postgres36 - DB_POSTGRESDB_PORT=543237 - DB_POSTGRESDB_DATABASE=n8n38 - DB_POSTGRESDB_USER=${POSTGRES_USER}39 - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}40 - EXECUTIONS_MODE=queue41 - QUEUE_BULL_REDIS_HOST=redis42 - N8N_ENCRYPTION_KEY=${ENCRYPTION_KEY}43 depends_on:44 - n8n45 - postgres46 - redis47 networks:48 - n8n-network49 restart: unless-stopped5051 postgres:52 image: postgres:1553 environment:54 - POSTGRES_USER=${POSTGRES_USER}55 - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}56 - POSTGRES_DB=n8n57 volumes:58 - postgres-data:/var/lib/postgresql/data59 networks:60 - n8n-network61 restart: unless-stopped6263 redis:64 image: redis:alpine65 volumes:66 - redis-data:/data67 networks:68 - n8n-network69 restart: unless-stopped7071volumes:72 n8n-data:73 postgres-data:74 redis-data:7576networks:77 n8n-network:78 driver: bridge79EOF8081# 2. Create the .env file82cat > .env << 'EOF'83# n8n Automation84N8N_USER=admin85N8N_PASSWORD=secure_admin_password86POSTGRES_USER=n8n87POSTGRES_PASSWORD=secure_postgres_password88ENCRYPTION_KEY=your-encryption-key8990# Generate key: openssl rand -hex 3291EOF9293# 3. Start the services94docker compose up -d9596# 4. View logs97docker compose logs -fOne-Liner
Run this command to download and set up the recipe in one step:
terminal
1curl -fsSL https://docker.recipes/api/recipes/n8n-automation/run | bashTroubleshooting
- n8n interface shows 'Database connection failed': Verify POSTGRES_USER and POSTGRES_PASSWORD environment variables match between n8n and postgres containers
- Workflows fail to execute with 'Queue connection timeout': Check that Redis container is running and QUEUE_BULL_REDIS_HOST points to the correct Redis service name
- n8n-worker container crashes with 'Encryption key mismatch': Ensure N8N_ENCRYPTION_KEY environment variable is identical across n8n and n8n-worker containers
- Workflows execute slowly or time out: Increase worker container resources or add additional n8n-worker containers for better load distribution
- PostgreSQL container fails to start with 'Data directory not empty': Remove existing postgres-data volume or set POSTGRES_DB environment variable correctly
- n8n shows 'Authentication failed' on startup: Generate a strong N8N_ENCRYPTION_KEY using openssl rand -base64 32 and update environment variables
Community Notes
Loading...
Loading notes...
Download Recipe Kit
Get all files in a ready-to-deploy package
Includes docker-compose.yml, .env template, README, and license
Components
n8npostgresqlredis
Tags
#n8n#automation#workflow#integrations#zapier-alternative
Category
Productivity & CollaborationAd Space
Shortcuts: C CopyF FavoriteD Download