Production Deployment
This page covers production deployment strategies for Automatos AI, with specific guidance for Railway deployment and general best practices applicable to any cloud platform. For local development setup, see Getting Started. For Docker containerization details, see Docker Containerization. For environment variable reference, see Environment Variables.
Deployment Overview
Automatos AI supports production deployment on cloud platforms using Docker containers. The system uses multi-stage Docker builds with optimized production images, centralized configuration management, and support for Railway's environment variable conventions.
Key Production Components:
Backend: FastAPI application on port 8000 (configurable via
PORTenv var)Frontend: Next.js application on port 3000
PostgreSQL: Database with pgvector extension
Redis: Optional caching and pub/sub service
S3: Plugin marketplace storage
Sources: orchestrator/config.py:1-285, README.md:1-115
Railway Deployment
Railway is the primary supported platform, with automatic detection of Railway-specific environment variables and deployment patterns.
Railway Project Structure
Railway-Specific Configuration:
Frontend
npm install --legacy-peer-deps && npm run build
npm start
Fixed: 3000
Backend
Auto (Dockerfile)
uvicorn main:app --host 0.0.0.0 --port $PORT --workers 4
Railway sets $PORT
PostgreSQL
Railway Plugin
-
Railway provides DATABASE_URL
Redis
Railway Plugin
-
Railway provides REDIS_URL
Sources: orchestrator/Dockerfile:73-116, frontend/Dockerfile:83-119, orchestrator/config.py:73-79
Deployment Steps
1. Create Railway Project
2. Add Database Plugins
Add PostgreSQL and Redis plugins in Railway dashboard:
PostgreSQL: Version 16 with pgvector support
Redis: Version 7 with persistence
Railway automatically injects DATABASE_URL and REDIS_URL environment variables.
3. Configure Environment Variables
Set these variables in Railway dashboard for backend service:
Required:
Optional:
For frontend service:
Sources: orchestrator/.env.example:1-64, orchestrator/config.py:28-185
4. Deploy Services
Railway automatically builds Docker images using multi-stage Dockerfiles and deploys to production infrastructure.
Production Docker Configuration
Multi-Stage Build Architecture
Both frontend and backend use multi-stage Docker builds with separate development and production targets.
Backend Production Stage
Key Production Optimizations:
Production Command:
This command:
Uses
$PORTenvironment variable (Railway requirement)Falls back to port 8000 if
PORTnot setRuns 4 worker processes for concurrency
Binds to all interfaces (
0.0.0.0)
Sources: orchestrator/Dockerfile:73-116
Frontend Production Stage
Key Frontend Optimizations:
Static optimization
Next.js SSG/ISR
Built into Next.js
Important: NEXT_PUBLIC_* environment variables are baked into the client bundle at build time and cannot contain secrets. Server-side API keys must be handled via backend API routes.
Sources: frontend/Dockerfile:51-119
Security Hardening
Production images implement multiple security layers:
Security Checklist:
✅ Non-root user for both frontend and backend
✅ Secrets injected at runtime (never in Dockerfile or code)
✅ Development dependencies removed in production
✅ Health checks for automatic restart on failure
✅ Encrypted credential storage (AES-256-GCM)
✅ API key authentication for backend
✅ Clerk JWT verification for user endpoints
Sources: orchestrator/Dockerfile:98-115, frontend/Dockerfile:103-118, orchestrator/core/credentials/service.py:1-850
Database Configuration
PostgreSQL Production Setup
Connection Pooling
The system uses SQLAlchemy with connection pooling configured for production workloads:
Recommended Pool Configuration:
pool_size
5
20
Base connection pool
max_overflow
10
30
Additional connections under load
pool_timeout
30
30
Seconds to wait for connection
pool_recycle
3600
1800
Recycle connections (seconds)
Sources: docker-compose.yml:21-42, orchestrator/config.py:36-42
pgvector Extension
Production PostgreSQL must have the pgvector extension enabled for embedding storage:
Railway PostgreSQL plugin includes pgvector by default when using pgvector/pgvector:pg16 image.
Backup Strategy
Automated Backups:
Railway provides automatic daily backups (retained 7 days)
Configure additional backup retention via Railway dashboard
Manual Backups:
Sources: docker-compose.yml:21-42
Redis Production Setup
Connection Configuration
Redis is optional but recommended for production to enable:
Plugin content caching
Real-time workflow updates (pub/sub)
Composio app/action caching
Railway REDIS_URL Format:
The RedisClient class automatically parses REDIS_URL with fallback to individual variables:
Sources: orchestrator/core/redis/client.py:149-198, orchestrator/config.py:46-62
Cache Policies
Production Redis is configured with LRU eviction for memory management:
Cache TTL Values:
Plugin content
3600 (1 hour)
PLUGIN_CACHE_TTL_SECONDS
Composio apps
86400 (24 hours)
ROUTING_CACHE_TTL_HOURS
Session data
Varies
Configured in application
Sources: docker-compose.yml:48-63, orchestrator/core/services/plugin_cache.py:38-47
Pub/Sub Channels
Redis pub/sub is used for real-time workflow execution updates:
Channel Naming Convention:
Message Format:
The RedisClient.publish_workflow_event() method handles message formatting and publishing.
Sources: orchestrator/core/redis/client.py:91-119
Secrets Management
Credential Encryption
Production credentials are encrypted using AES-256-GCM with workspace-scoped encryption keys.
Encryption Architecture
Encryption Key Setup:
Security Features:
AES-256-GCM encryption
Workspace-scoped credential isolation
Audit logging for all access
Automatic key rotation support
Expiration date enforcement
Sources: orchestrator/core/credentials/service.py:42-182, orchestrator/core/models/credentials.py:60-103
API Key Rotation
Production API keys should be rotated periodically:
The get_request_context_hybrid authentication middleware supports API key validation:
Sources: orchestrator/config.py:66-68
CORS Configuration
Production CORS must explicitly allow frontend domains:
The Config class automatically parses and validates CORS origins:
Sources: orchestrator/config.py:71-79
Health Checks & Monitoring
Health Endpoints
Both frontend and backend include health check endpoints for monitoring and auto-restart.
Backend Health Check
Docker Health Check Configuration:
Sources: orchestrator/Dockerfile:106-108
Frontend Health Check
Health Check Configuration:
Sources: frontend/Dockerfile:112-114
Railway Monitoring
Railway provides built-in monitoring:
Metrics: CPU, memory, network usage
Logs: Aggregated stdout/stderr from all services
Deployments: Automatic rollback on health check failures
Alerts: Configure alerts for downtime or errors
Access Logs:
Scaling Considerations
Horizontal Scaling
Backend Worker Processes
Production backend runs multiple Uvicorn workers:
Worker Count Recommendations:
Small (Railway Hobby)
2
256 MB
512 MB
Medium (Railway Pro)
4
512 MB
2 GB
Large (Railway Enterprise)
8
1 GB
8 GB
Formula: workers = (2 * num_cpu_cores) + 1
Sources: orchestrator/Dockerfile:115
Database Connection Pooling
Each worker maintains its own connection pool. Ensure PostgreSQL max_connections accommodates all workers:
Example for 2 backend instances with 4 workers each:
Set max_connections=200 in PostgreSQL configuration for safety margin.
Sources: docker-compose.yml:29
Redis Connection Management
Redis uses connection pooling to handle concurrent requests:
For multiple backend instances, increase max_connections:
Sources: orchestrator/core/redis/client.py:22-29
Vertical Scaling
Railway allows easy vertical scaling through the dashboard:
Resource Limits:
Hobby
Shared
512 MB - 8 GB
100 GB
Pro
Shared
512 MB - 32 GB
100 GB
Enterprise
Dedicated
Custom
Custom
Scaling Guidelines:
Monitor resource usage via Railway dashboard
Scale memory first if OOM errors occur
Scale CPU if high latency with low memory usage
Increase workers if CPU utilization < 70% but response time is slow
Environment-Specific Configuration
Production vs Development
The Config class provides environment detection:
Key Differences:
ENVIRONMENT
development
production
LOG_LEVEL
DEBUG
INFO or WARNING
DEBUG
true
false
Docker target
development
production
Hot reload
Enabled
Disabled
Source mounts
Yes
No
Optimization
None
Multi-stage, cleaned
Sources: orchestrator/config.py:114-123
Feature Flags
Production deployments can enable/disable features via environment variables:
Feature flags are centralized in the Config class:
Sources: orchestrator/config.py:154-174
Troubleshooting Production Issues
Common Issues
1. Backend Fails to Start
Symptoms:
Health check failures
Crash loop in Railway logs
Diagnosis:
Solutions:
Database connection failed
Verify DATABASE_URL is set and PostgreSQL plugin is running
Redis connection failed
Redis is optional; set REDIS_URL or remove Redis dependencies
Failed to decrypt credentials
Set ENCRYPTION_KEY environment variable
Import errors
Ensure all dependencies in requirements.txt are installed
2. Frontend Cannot Connect to Backend
Symptoms:
"Failed to fetch" errors in browser console
CORS errors
Solutions:
Verify
NEXT_PUBLIC_API_URLpoints to backend service URLCheck CORS configuration includes frontend domain
Ensure backend service is healthy (check
/healthendpoint)
3. Slow Database Queries
Diagnosis:
Solutions:
Increase
max_connectionsin PostgreSQLIncrease connection pool size in application
Add database indexes for slow queries
Enable query logging to identify bottlenecks
4. Redis Connection Timeouts
Symptoms:
Workflow updates not streaming
Plugin content cache misses
Solutions:
Sources: orchestrator/core/redis/client.py:121-134, docs/LOCAL_SETUP_GUIDE.md:145-175
Deployment Checklist
Before deploying to production:
Pre-Deployment
Post-Deployment
Monitoring
Sources: orchestrator/config.py:225-247, orchestrator/.env.example:1-64
Last updated

