This system provides dynamic scaling for n8n worker containers based on the length of your Redis queue. It eliminates the need for Kubernetes or heavy orchestration by using a lightweight script to monitor the queue and adjust container counts on the fly. Built on a Docker Compose foundation, the setup has been verified on an 8-core, 16GB VPS and is capable of managing hundreds of concurrent executions.
The architecture connects several key components: the primary n8n instance pushes jobs into a Redis queue, while a dedicated autoscaler and a Redis monitor track the queue's activity. Depending on the queue depth, the autoscaler adds or removes worker containers as needed. PostgreSQL serves as the persistent data store, and the main n8n instance is configured to communicate with an n8n webhook service.
Ensure that Docker and Docker Compose are installed on your system. If you are on Ubuntu, you can use the official convenience script; otherwise, Docker Desktop is recommended for local environments.
.env file. While the defaults are functional for testing, you should update passwords and security tokens for any production use.docker compose up -d..env file before going live.N8N_CONCURRENCY_PRODUCTION_LIMIT=10 in the docker-compose.yml file.N8N_QUEUE_BULL_GRACEFULSHUTDOWNTIMEOUT=300 and N8N_GRACEFUL_SHUTDOWN_TIMEOUT=300 (in seconds). These should be set to a duration longer than your longest-running workflow to prevent data loss during scaling events.| Variable | Description | Default |
|---|---|---|
MIN_REPLICAS |
Minimum number of active worker containers | 1 |
MAX_REPLICAS |
Maximum number of worker containers allowed | 5 |
SCALE_UP_QUEUE_THRESHOLD |
Queue length required to trigger a scale-up action | 5 |
SCALE_DOWN_QUEUE_THRESHOLD |
Queue length required to trigger a scale-down action | 2 |
POLLING_INTERVAL_SECONDS |
Frequency (in seconds) of queue depth checks | 30 |
COOLDOWN_PERIOD_SECONDS |
Minimum wait time between consecutive scaling actions | 180 |
QUEUE_NAME_PREFIX |
Prefix used for the Redis queue | bull |
QUEUE_NAME |
Name of the target Redis queue | jobs |
EXECUTIONS_MODE=queue
QUEUE_BULL_REDIS_HOST=redis
QUEUE_HEALTH_CHECK_ACTIVE=true
The autoscaler evaluates the Redis queue at every POLLING_INTERVAL_SECONDS.
Scaling Up: If the queue length exceeds the SCALE_UP_QUEUE_THRESHOLD and the worker count is currently below MAX_REPLICAS, the autoscaler launches additional workers.
Scaling Down: If the queue length drops below the SCALE_DOWN_QUEUE_THRESHOLD and the worker count is above MIN_REPLICAS, the autoscaler terminates excess containers.
A cooldown period is enforced after every scaling event to prevent "thrashing"—the rapid, unnecessary starting and stopping of containers due to minor fluctuations in the queue.
Monitoring. The system includes a dedicated Redis monitor service. You can track the health of all services via Docker health checks, and the autoscaler provides detailed activity logs for auditing.
Troubleshooting Tips
docker-compose logs [service_name]docker-compose exec redis redis-cli pingdocker-compose exec redis redis-cli LLEN bull:jobs:waitImportant Note on Webhook URLs: When configuring webhooks within this setup, use the Docker service name rather than localhost. For example: http://n8n-webhook:5678/webhook/[unique-id].
AgentFlow: Modular AI Agent Framework Outperforms GPT-4o
BitzNet SD-WAN: Secure SD-WAN for Faster, Safer Internet Access
Duck VPN Review: Stream Netflix & Unblock Social Apps Without Logs
NeuralAgent: An Open-Source AI Agent for Native Desktop Automation
Easy Agents: Automate Operations with Natural Language and MCP
PandaWiki Setup Guide: Building an AI-Powered Knowledge Base
Jessibuca Setup Guide: H5 Player Configuration, Decoding Modes, and Troubleshooting
Crawl4AI: Fast LLM-Ready Web Scraping Without the Bloat
Gmail AutoAuth MCP Server: Control Gmail via Claude Desktop
MusicFree: A Modular Open-Source Music Player for Android and HarmonyOS
Add Area Fill to Line Charts in Excel: Step-by-Step
Spacedrive: An Open-Source Cross-Platform File Manager