Scaling Architecture
Activepieces can be scaled by separating concerns into specialized containers:Container Types
Activepieces supports three container types via theAP_CONTAINER_TYPE environment variable:
- WORKER_AND_APP (Default)
- APP
- WORKER
All-in-one containerRuns both API server and background workers:Use for:
- Development
- Small deployments (< 100 workflows)
- Single server setups
- Simple configuration
- Minimal resource overhead
- Limited scalability
- API and workers compete for resources
Horizontal Scaling Strategies
Strategy 1: Multiple All-in-One Instances
Simple scaling - Run multipleWORKER_AND_APP containers:
docker-compose.yml
nginx.conf
Strategy 2: Separate APP and WORKER Containers
Recommended for production - Dedicated containers:docker-compose.yml
Benefits:
- Scale API and workers independently
- Optimize resource allocation
- Better fault isolation
- Easier monitoring
Kubernetes Scaling
Horizontal Pod Autoscaler
Automatically scale based on CPU/memory:Helm Configuration
values.yaml
Worker Configuration
Worker Concurrency
Control how many jobs each worker processes simultaneously:.env
Guidelines:
- CPU-bound workflows:
concurrency = CPU cores - I/O-bound workflows:
concurrency = CPU cores × 2-4 - Default: 1 (safe default)
- 2 CPU cores, CPU-intensive:
concurrency = 2 - 4 CPU cores, API calls/webhooks:
concurrency = 8-16
PM2 Clustering
Enable process clustering within a container:.env
When
AP_PM2_ENABLED=true, PM2 starts one process per CPU core using cluster mode with -i 0.See docker-entrypoint.sh:20 for implementation.Database Scaling
Connection Pooling
Adjust pool size based on instance count:PostgreSQL Max Connections
Increase PostgreSQL max connections:- AWS RDS
- Google Cloud SQL
- Azure Database
Parameter Groups →
max_connectionsFormula: {DBInstanceClassMemory/9531392}Read Replicas
Offload read queries to replicas:.env
Redis Scaling
Redis Cluster
For high-throughput deployments, use Redis Cluster:.env
Redis Sentinel
For high availability:.env
Job Retention
Control queue memory usage:.env
Load Balancing
Nginx
Kubernetes Ingress
Monitoring Scaling
Metrics to Monitor
Queue Metrics
Queue Metrics
Monitor Redis queue depth:Scale workers when:
- Waiting jobs > 100
- Average wait time > 30s
Worker Utilization
Worker Utilization
Monitor worker CPU/memory:Scale when:
- CPU > 80%
- Memory > 80%
API Response Time
API Response Time
Monitor API latency:Scale APP containers when:
- p95 latency > 500ms
- Error rate > 1%
Database Connections
Database Connections
Monitor PostgreSQL connections:Adjust when:
- Active > 80% of max
- Connection errors in logs
Queue UI
Enable BullMQ Board for visual monitoring:.env
http://your-domain/admin/queues
Performance Optimization
Execution Mode
Use sandboxed execution for production:.env
Timeouts
Adjust based on your workflow needs:.env
Caching
Enable piece caching:.env
Scaling Checklist
Database
- Increase
max_connectionsin PostgreSQL - Adjust
AP_POSTGRES_POOL_SIZEper instance - Enable connection pooling (PgBouncer)
- Setup database replication for HA
Redis
- Configure Redis persistence
- Setup Redis Sentinel/Cluster for HA
- Monitor queue depth
- Configure job retention
Application
- Separate APP and WORKER containers
- Configure worker concurrency
- Enable PM2 for APP containers
- Setup load balancer
Next Steps
Workers
Deep dive into worker architecture
Architecture
Understand system components
Database
Optimize database performance
Monitoring
Setup monitoring and alerts