Deployment Overview
This guide covers the essential requirements and considerations for deploying a Medusa application to production.Requirements
Node.js Version
Medusa requires Node.js 20 or higher. Make sure your production environment meets this requirement:PostgreSQL Database
Medusa uses PostgreSQL as its primary database. Your production environment needs:- PostgreSQL 12 or higher (PostgreSQL 14+ recommended)
- Database user with create privileges
- Network access from your Medusa application to the database
Redis (Optional but Recommended)
For production environments, Redis is recommended for:- Event Bus: Reliable event processing
- Cache: Improved performance
- Workflow Engine: Distributed workflow execution
- Locking: Distributed locks for concurrent operations
Deployment Options
Self-Hosted
Deploy Medusa on your own infrastructure:- Virtual Private Server (VPS): DigitalOcean, Linode, Vultr
- Cloud Providers: AWS EC2, Google Cloud Compute Engine, Azure VMs
- Containerized: Docker, Kubernetes
- Platform as a Service: Heroku, Railway, Render
Medusa Cloud
Medusa Cloud provides managed hosting with:- Automatic scaling
- Built-in Redis and PostgreSQL
- Integrated monitoring and logging
- Simplified deployment workflow
EXECUTION_CONTEXT=medusa-cloud to enable cloud-specific configurations.
Production Considerations
Environment Variables
Always use environment variables for sensitive configuration like database credentials, API keys, and secrets. Never commit these to version control.
Database Migrations
Before starting your application in production, always run migrations:- Creates the database if it doesn’t exist
- Runs all pending module migrations
- Synchronizes link definitions
- Executes migration scripts
Build Process
For production deployments, build your application:- Compiles TypeScript to JavaScript
- Bundles the admin dashboard (if enabled)
- Optimizes dependencies
Worker Mode
Medusa supports different worker modes for scaling:shared(default): Single process handles both HTTP and background jobsserver: Process only handles HTTP requestsworker: Process only handles background jobs
Health Checks
Implement health checks for your deployment:Monitoring and Logging
Configure logging level for production:Use
error or warn in production to reduce log volume. Use debug only for troubleshooting.Security Best Practices
Secrets Management
- Generate strong secrets: Use at least 32 random characters for
JWT_SECRETandCOOKIE_SECRET - Rotate secrets regularly: Update secrets periodically and after any security incidents
- Use environment-specific secrets: Different secrets for development, staging, and production
CORS Configuration
Properly configure CORS for your domains:HTTPS
Always use HTTPS in production:- Use a reverse proxy (nginx, Caddy, Traefik)
- Configure SSL/TLS certificates (Let’s Encrypt recommended)
- Enable HTTP to HTTPS redirects
Next Steps
Configuration
Learn how to configure Medusa via medusa-config.js
Database Setup
PostgreSQL configuration and migrations
Environment Variables
Complete reference of all environment variables