N8N Queue Mode - Cost Optimization Guide¶
Cost Breakdown¶
Worker Costs (Azure Container Apps)¶
Each N8N worker (1 vCPU, 2GB RAM) costs approximately: - ~$75/month running 24/7 - ~$2.50/day running 24/7 - ~$0.10/hour when running
Configuration Options¶
Option 1: Min=0, Max=10 ⭐ RECOMMENDED FOR COST SAVINGS¶
# Deploy with zero minimum workers
./scripts/deploy-n8n-queue-mode.sh deploy-workers
# Or set in environment
export WORKER_MIN_REPLICAS=0
export WORKER_MAX_REPLICAS=10
Monthly Costs: - Main instance: $30/month (always running) - Workers when idle: $0/month - Workers during business hours (avg 2): ~$150/month - Total idle cost: $30/month - Total business hours: $180/month
Annual Savings: ~$1,440/year vs Min=2 (assuming 50% idle time)
Best for: - ✅ Development/staging environments - ✅ Intermittent workflow usage - ✅ Scheduled workflows (predictable timing) - ✅ Cost-sensitive deployments
Trade-off: - ⚠️ Cold start delay: 30-60 seconds for first workflow after idle period - First worker takes time to spin up, pull image, and start
Mitigation: - Use scheduled workflows to "warm up" workers before peak hours - Set higher min replicas during business hours only (see schedule-based scaling below)
Option 2: Min=1, Max=10 (Balanced)¶
export WORKER_MIN_REPLICAS=1
export WORKER_MAX_REPLICAS=10
./scripts/deploy-n8n-queue-mode.sh deploy-workers
Monthly Costs: - Main instance: $30/month - 1 worker (always): $75/month - Additional workers during peaks: $0-675/month - Total baseline: $105/month
Annual Savings: ~$540/year vs Min=2
Best for: - ✅ Production with time-sensitive workflows - ✅ Need immediate execution without cold start - ✅ Balance between cost and performance
Option 3: Min=2, Max=10 (High Availability)¶
export WORKER_MIN_REPLICAS=2
export WORKER_MAX_REPLICAS=10
./scripts/deploy-n8n-queue-mode.sh deploy-workers
Monthly Costs: - Main instance: $30/month - 2 workers (always): $150/month - Additional workers during peaks: $0-600/month - Total baseline: $180/month
Best for: - ✅ Production with high availability requirements - ✅ Parallel workflows needed immediately - ✅ Redundancy if one worker fails
Advanced Cost Optimization Strategies¶
1. Schedule-Based Scaling (Business Hours Only)¶
Use Azure CLI to change scaling based on time of day:
Morning Scale-Up (8 AM, weekdays):
# Run this via Azure Automation or GitHub Actions on schedule
az containerapp update \
--name slidefactory-n8n-worker \
--resource-group rg-slidefactory-prod-001 \
--min-replicas 2 \
--max-replicas 10
Evening Scale-Down (6 PM, weekdays):
az containerapp update \
--name slidefactory-n8n-worker \
--resource-group rg-slidefactory-prod-001 \
--min-replicas 0 \
--max-replicas 5
Weekend Scale-Down:
az containerapp update \
--name slidefactory-n8n-worker \
--resource-group rg-slidefactory-prod-001 \
--min-replicas 0 \
--max-replicas 2
Potential Savings: Up to 70% reduction in worker costs
2. Queue-Based Scaling (Future Enhancement)¶
Add custom scaling rule based on Redis queue depth:
az containerapp update \
--name slidefactory-n8n-worker \
--resource-group rg-slidefactory-prod-001 \
--scale-rule-name queue-depth \
--scale-rule-type azure-queue \
--scale-rule-metadata "queueName=bull:n8n:waiting" "queueLength=10"
Scale up when queue has 10+ pending jobs.
3. Resource Right-Sizing¶
If workflows are lightweight, reduce worker resources:
export WORKER_CPU="0.5"
export WORKER_MEMORY="1.0Gi"
./scripts/deploy-n8n-queue-mode.sh deploy-workers
Cost per worker: ~$37.50/month (50% savings per worker)
Warning: Only if your workflows don't need full resources.
4. Azure Reserved Instances¶
For predictable baseline (e.g., Min=1): - Purchase 1-year or 3-year Azure Reserved Capacity - Savings: 30-50% discount on committed resources - Example: 1 worker reserved = ~$25-40/month instead of $75/month
5. Development/Staging Optimization¶
For non-production environments:
# Ultra-low cost config
export WORKER_MIN_REPLICAS=0
export WORKER_MAX_REPLICAS=2
export WORKER_CPU="0.5"
export WORKER_MEMORY="1.0Gi"
Cost: $30/month (main only) when idle, $105/month at peak (2 workers)
Cost Comparison: Annual Estimate¶
| Configuration | Idle Hours (50%) | Business Hours (40%) | Peak Hours (10%) | Annual Total |
|---|---|---|---|---|
| Min=0 | $180 | $864 | $936 | $1,980 |
| Min=1 | $630 | $1,080 | $936 | $2,646 |
| Min=2 | $1,080 | $1,296 | $936 | $3,312 |
| Min=2 (current regular mode) | $360 | $360 | $360 | $1,080 (no scaling) |
Note: Min=0 with queue mode is still more expensive than current regular mode, but provides 3-5x throughput during business hours.
Recommended Strategy by Environment¶
Production¶
Cost: ~$105-225/month Reason: Balance of performance and costPreview/Staging¶
Cost: ~$30-180/month Reason: Test scalability without high costsDevelopment¶
Cost: ~$30-105/month Reason: Minimal cost for testingMonitoring Costs¶
View Current Worker Count¶
az containerapp revision list \
--name slidefactory-n8n-worker \
--resource-group rg-slidefactory-prod-001 \
--query "[?properties.active].{name:name, replicas:properties.replicas}" \
-o table
Check Scaling Events¶
az monitor activity-log list \
--resource-group rg-slidefactory-prod-001 \
--namespace Microsoft.App/containerApps \
--max-events 50 \
--query "[?contains(resourceId, 'slidefactory-n8n-worker')]" \
-o table
Set Budget Alert¶
az consumption budget create \
--budget-name n8n-workers-monthly \
--amount 300 \
--time-grain Monthly \
--resource-group rg-slidefactory-prod-001 \
--notifications enabled=true threshold=80 contactEmails=your-email@example.com
Cold Start Deep Dive¶
What Happens with Min=0?¶
When no workers are running and a workflow is triggered:
- N8N Main receives workflow execution request
- N8N Main publishes job to Redis queue (
bull:n8n:waiting) - Azure Container Apps detects queue activity (if using queue-based scaling) or other trigger
- Azure spins up first worker container (~30-60 seconds)
- Pull N8N Docker image (if not cached)
- Start container
- N8N worker connects to Redis
- Worker connects to PostgreSQL
- Worker starts listening for jobs
- Worker pulls job from queue and executes workflow
Total delay: 30-90 seconds for first workflow after idle period
Reducing Cold Start Impact¶
Option 1: Warm-up Workflow Create a scheduled N8N workflow that runs every 15 minutes during business hours:
This keeps at least 1 worker alive during business hours.Option 2: Pre-warming Script Run before known workflow executions:
# Execute a dummy workflow to warm up workers
curl -X POST https://slidefactory-n8n.../api/v1/workflows/dummy-warmup/execute \
-H "X-N8N-API-KEY: $N8N_API_KEY"
Option 3: Use Min=1 During Business Hours Via scheduled Azure Automation or GitHub Actions.
Decision Matrix¶
| If you need... | Use Config | Monthly Cost | Trade-off |
|---|---|---|---|
| Lowest cost | Min=0, Max=5 | $30-180 | Cold start |
| No cold start | Min=1, Max=10 | $105-225 | Higher baseline |
| High availability | Min=2, Max=10 | $180-330 | Highest cost |
| Peak performance | Min=2, Max=20 | $180-600 | Very high cost |
Quick Commands¶
Deploy with Min=0 (Cost Optimized)¶
export WORKER_MIN_REPLICAS=0
export WORKER_MAX_REPLICAS=10
./scripts/deploy-n8n-queue-mode.sh deploy-workers
Deploy with Min=1 (Balanced)¶
export WORKER_MIN_REPLICAS=1
export WORKER_MAX_REPLICAS=10
./scripts/deploy-n8n-queue-mode.sh deploy-workers
Change Scaling On-the-Fly¶
az containerapp update \
--name slidefactory-n8n-worker \
--resource-group rg-slidefactory-prod-001 \
--min-replicas 0
Summary¶
💰 Maximum Cost Savings: Min=0, Max=10 - Annual savings: ~$1,440/year vs Min=2 - Best for: Intermittent usage, development/staging - Trade-off: 30-60 second cold start
⚖️ Balanced: Min=1, Max=10 (Recommended for Production) - Annual savings: ~$540/year vs Min=2 - Best for: Production with time-sensitive workflows - Trade-off: Small baseline cost, no cold start
🚀 High Availability: Min=2, Max=10 - Best for: Critical production workloads - Trade-off: Higher cost, immediate redundancy
Last Updated: 2025-11-25