Deployment & Production Setup
Relevant source files
The following files were used as context for generating this wiki page:
OpenAlgo is a production-grade algorithmic trading platform designed for self-hosting. The platform architecture is built around a Flask backend and a React 19 frontend, utilizing a single-user deployment model where one instance manages one broker session and one WebSocket feed. Production deployments are optimized for Linux environments, supporting both native systemd service management and Docker containerization.
The deployment infrastructure is designed to handle high-concurrency market data via a ZeroMQ bus and WebSocket proxy, ensuring the trading engine remains responsive regardless of client connection speeds. Security is a primary concern, with automated SSL certificate provisioning via Let's Encrypt and strict firewall configurations.
Sources: CLAUDE.md:14-25, install/install.sh:370-385
Production Architecture
The production architecture follows a multi-layered approach to ensure stability and performance. It utilizes Nginx as a reverse proxy to handle SSL termination, rate limiting, and request routing to the internal application components.
Component Overview
- Nginx Reverse Proxy: Acts as the entry point, handling HTTPS (port 443) and WSS. It routes traffic to the Flask application and the WebSocket proxy.
- Flask Application: The core logic server, running under Gunicorn with the
eventletworker class. - WebSocket Proxy: A dedicated service (port 8765) managing real-time market data streaming to clients.
- ZeroMQ Bus: An internal message bus (port 5555) that decouples broker data adapters from the WebSocket delivery layer.
The diagram shows the request flow from the user through the security and proxy layers to the internal trading engine components.
Sources: CLAUDE.md:95-105, install/install-docker.sh:780-805
Deployment Modes
OpenAlgo supports two primary production deployment methods: Native Linux installation and Docker-based containerization.
Native Systemd Deployment
This mode installs OpenAlgo directly on a Linux server (Ubuntu/Debian/Arch/RHEL). It uses uv for Python dependency management and systemd to manage the lifecycle of the Gunicorn process.
| Feature | Implementation |
|---|---|
| Process Manager | systemd (openalgo.service) |
| Python Env | uv venv |
| IPC | Unix Domain Socket (openalgo.sock) |
| Workers | Gunicorn + Eventlet (1 worker mandatory) |
Sources: install/install.sh:445-460, CLAUDE.md:65-75
Docker Deployment
The Docker deployment containerizes the entire stack, providing isolation and simplified dependency management. It is particularly useful for environments requiring consistent runtime libraries for numba and llvmlite.
The Docker architecture utilizes named volumes for data persistence while keeping the application logic isolated within the container.
Sources: install/install-docker.sh:390-425, docker-build.sh:125-145
Configuration & Environment
Configuration is strictly managed via a .env file. On production start, the system performs an env_check to ensure critical security keys are not using default placeholders.
Critical Security Keys
| Variable | Purpose |
|---|---|
APP_KEY | Core application encryption key |
API_KEY_PEPPER | Hashing pepper for stored API keys |
TRUST_PROXY_HEADERS | Set to TRUE when behind Nginx to see real client IPs |
CORS_ALLOWED_ORIGINS | Comma-separated list of allowed domains |
Sources: install/install.sh:530-555, install/install-docker.sh:305-330
Resource Optimization
The deployment scripts automatically calculate resource limits based on host specifications to prevent RLIMIT_NPROC exhaustion, especially for numba and numpy operations.
- Shared Memory (
shm_size): Set to 25% of system RAM (min 256MB, max 2GB). - Thread Limits:
OPENBLAS_NUM_THREADSandOMP_NUM_THREADSare capped based on available CPU cores and RAM to ensure stability of strategy subprocesses.
Sources: install/install-docker.sh:365-385, install/install.sh:845-860
Network & Security Setup
Production setup enforces strict networking rules to protect the trading engine and sensitive broker credentials.
Port Management
| Port | Accessibility | Service |
|---|---|---|
| 443 | Public | HTTPS / WSS (Nginx) |
| 80 | Public | HTTP (Redirect to HTTPS / Certbot) |
| 5000 | Localhost Only | Flask Backend (Internal) |
| 8765 | Localhost Only | WebSocket Proxy (Internal) |
| 5555 | Localhost Only | ZeroMQ Bus (Strictly Internal) |
Sources: install/install-docker.sh:735-750, CLAUDE.md:107-115
SSL & WebSocket Proxying
Nginx is configured with specific proxy_set_header directives to support persistent WebSocket connections. In production, proxy_read_timeout and proxy_send_timeout are set to 86400s (24 hours) to maintain stable market data feeds.
location /ws/ {
proxy_pass http://127.0.0.1:8765/;
proxy_http_version 1.1;
proxy_read_timeout 86400s;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
Sources: install/install.sh:765-790, install/install-docker.sh:610-635
Maintenance & Updates
Database Migrations
Schema changes are managed via migration scripts in the upgrade/ directory. The deployment system requires migrations to be idempotent. In Docker environments, migrate_all.py runs automatically on container start.
Update Workflow
- Backup: Databases (
.db,.duckdb) are backed up to a timestamped directory. - Pull: Latest code is fetched from
main. Local changes are stashed automatically. - Sync: Python dependencies are updated via
uv pip install. - Migrate:
upgrade/migrate_all.pyis executed to apply schema changes. - Restart: The systemd service or Docker container is restarted to apply changes.
Sources: install/update.sh:195-250, install/install-docker.sh:220-235, CLAUDE.md:148-165
Conclusion
Deployment and production setup for OpenAlgo centers on high-performance market data handling and rigorous security. By leveraging Nginx for traffic management and uv for dependency isolation, the platform ensures a stable environment for automated trading. Whether using native systemd services or Docker containers, the architecture maintains strict internal component isolation via ZeroMQ and controlled port exposure.