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].
XunLong Review: AI Content Engine That Writes Reports, Fiction & Decks
Qwen3-ASR-Toolkit: Transcribe Long Audio Files Beyond the 3-Minute Limit
PromptEnhancer: Rewrite Any Prompt for Stunning AI Images
Cogency: Build AI Agents in Python with Transparent ReAct Loops
UTCP Explained: A Universal Tool Calling Protocol for APIs, LLMs, and Beyond
LandPPT: Create AI-Powered Presentations from Any Document
Turso Database: A Rust-Based SQLite-Compatible Engine
Koishi Chatbot Framework: Build a Cross-Platform Bot in Minutes
Mevzuat MCP: Search Turkish Legislation Directly in Claude
AI看线: A-Share Analysis with K-Line Charts and Gemini AI Forecasts
n8n Automation: Over 400 AI Integrations in a Single Workflow
ZeroSearch: Training LLMs to Search Without Real-World Search Engines