medusa-deploy
Deploy Medusa v2 to production — build process, server vs worker mode, environment variables, hosting options, Redis caching, database configuration, and production checklist. Use when deploying Medusa applications.
Best use case
medusa-deploy is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Deploy Medusa v2 to production — build process, server vs worker mode, environment variables, hosting options, Redis caching, database configuration, and production checklist. Use when deploying Medusa applications.
Teams using medusa-deploy should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/medusa-deploy/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How medusa-deploy Compares
| Feature / Agent | medusa-deploy | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Deploy Medusa v2 to production — build process, server vs worker mode, environment variables, hosting options, Redis caching, database configuration, and production checklist. Use when deploying Medusa applications.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Medusa v2 Deployment ## Before writing code **Fetch live docs**: 1. Web-search `site:docs.medusajs.com deployment production` for production deployment guides 2. Web-search `site:docs.medusajs.com medusa build` for build process details 3. Fetch `https://docs.medusajs.com/learn/fundamentals/cli` for CLI command reference 4. Web-search `site:docs.medusajs.com environment variables configuration` for env var reference 5. Web-search `site:docs.medusajs.com redis cache events` for Redis caching and event bus setup ## Build Process ### Build Commands | Command | Purpose | |---------|---------| | `npx medusa build` | Compile server + admin dashboard for production | | `npx medusa db:migrate` | Run pending database migrations | | `npx medusa start` | Start the production server | | `npx medusa worker` | Start the background worker process | The build step compiles TypeScript, bundles admin extensions (Vite), and prepares the `.medusa/` output directory. ### Build Output Structure ``` .medusa/ ├── server/ — Compiled server code │ ├── src/ — Custom modules, routes, workflows │ └── medusa-config.js └── admin/ — Bundled admin dashboard (static) ``` ## Server vs Worker Mode Medusa v2 supports running the server and background workers as separate processes: | Mode | Command | Handles | |------|---------|---------| | **Server** | `npx medusa start` | HTTP requests, API routes, admin dashboard | | **Worker** | `npx medusa worker` | Workflows, scheduled jobs, event subscribers | | **Combined** | Default `start` behavior | Both server and worker (single process) | ### When to Separate - **Development** — combined mode is fine - **Production** — separate for reliability and independent scaling - **High traffic** — scale server instances independently from workers - Worker mode requires Redis for job queue communication between processes ## Environment Variables ### Required Variables | Variable | Purpose | Example | |----------|---------|---------| | `DATABASE_URL` | PostgreSQL connection string | `postgres://user:pass@host:5432/medusa` | | `COOKIE_SECRET` | Session cookie signing | Random 32+ character string | | `JWT_SECRET` | JWT token signing | Random 32+ character string | | `NODE_ENV` | Runtime environment | `production` | ### Optional but Recommended | Variable | Purpose | Default | |----------|---------|---------| | `REDIS_URL` | Redis connection for cache/events/workers | None (in-memory) | | `STORE_CORS` | Store API CORS origins | `http://localhost:8000` | | `ADMIN_CORS` | Admin API CORS origins | `http://localhost:9000` | | `AUTH_CORS` | Auth route CORS origins | Combination of store + admin | | `PORT` | Server listen port | `9000` | | `MEDUSA_ADMIN_ONBOARDING_TYPE` | Admin onboarding flow | `default` | | `MEDUSA_WORKER_MODE` | `server`, `worker`, or `shared` | `shared` | ## Database Configuration ### PostgreSQL Requirements - PostgreSQL required (see official docs for version compatibility) - Enable SSL in production: append `?sslmode=require` to `DATABASE_URL` - Connection pooling recommended for high-traffic deployments ### Migration Workflow ```bash # Generate migration after DML model changes npx medusa db:generate <module_name> # Apply migrations npx medusa db:migrate ``` - Always run migrations before starting the new server version - Back up the database before running migrations in production - Test migrations against a staging database first ## Redis Configuration Redis serves three roles in production Medusa: | Role | Purpose | Required? | |------|---------|-----------| | **Event Bus** | Pub/sub for event-driven subscribers | Recommended | | **Cache** | Module data caching layer | Recommended | | **Worker Queue** | Job queue for background workflows | Required for worker mode | Configure in `medusa-config.ts` by registering the Redis modules: ```ts // Fetch live docs for Redis module registration // in medusa-config.ts modules array ``` - Use separate Redis databases (db index) for cache vs events vs queues - Set appropriate `maxmemory` and eviction policies for cache - Monitor Redis memory usage and connection count in production ## Hosting Options | Platform | Type | Notes | |----------|------|-------| | **Railway** | PaaS | One-click deploy, managed PostgreSQL and Redis | | **DigitalOcean App Platform** | PaaS | Managed infrastructure, auto-scaling | | **AWS (EC2/ECS/Fargate)** | IaaS/CaaS | Full control, use with RDS and ElastiCache | | **Google Cloud Run** | Serverless containers | Auto-scaling, pay-per-use | | **Render** | PaaS | Simple deploy, managed databases | | **Self-hosted (Docker)** | Container | Full control, use Docker Compose or Kubernetes | | **Vercel** | Serverless | Admin/storefront hosting only (not the Medusa server) | ### Docker Deployment ```dockerfile # Fetch live docs for official Medusa Dockerfile # and docker-compose.yml patterns ``` A typical Docker Compose setup includes three services: Medusa server, PostgreSQL, and Redis. ## Production Checklist ### Pre-Deploy - [ ] Set `NODE_ENV=production` - [ ] Configure unique `COOKIE_SECRET` and `JWT_SECRET` - [ ] Set `DATABASE_URL` with SSL mode enabled - [ ] Configure `REDIS_URL` for events, cache, and worker queue - [ ] Set CORS variables (`STORE_CORS`, `ADMIN_CORS`, `AUTH_CORS`) - [ ] Run `npx medusa build` successfully - [ ] Run `npx medusa db:migrate` against production database ### Infrastructure - [ ] PostgreSQL with automated backups and point-in-time recovery - [ ] Redis with persistence enabled (RDB or AOF) - [ ] HTTPS termination (TLS certificate) via reverse proxy or load balancer - [ ] Health check endpoint configured for load balancer - [ ] Log aggregation (stdout/stderr to centralized logging) ### Post-Deploy - [ ] Verify admin dashboard loads and login works - [ ] Verify store API responds with publishable key - [ ] Confirm background workers are processing jobs - [ ] Test payment provider webhooks reach the server - [ ] Monitor error rates and response times ## Scaling Strategies ### Horizontal Scaling - Run multiple server instances behind a load balancer - Use Redis-backed sessions for sticky-session-free scaling - Run multiple worker instances for parallel job processing ### Vertical Scaling - Increase PostgreSQL connection pool size for heavier workloads - Allocate more memory to Redis for larger cache datasets - Use `--max-old-space-size` for Node.js memory limits ## Best Practices - **Separate server and worker** — run as independent processes in production; scale each based on demand; use Redis as the communication backbone - **Environment variable hygiene** — never commit secrets to source control; use platform-native secret management (AWS Secrets Manager, Railway variables, etc.); rotate secrets periodically - **Database management** — always test migrations on staging first; automate backups; use connection pooling (PgBouncer) for high concurrency - **Monitoring** — track API response times, worker queue depth, database connection count, and Redis memory; set alerts for anomalies Fetch the Medusa deployment documentation for exact build flags, Docker configuration, and platform-specific deployment guides before deploying.
Related Skills
woo-deploy
Deploy WooCommerce — WP-CLI automation, database migrations, zero-downtime updates, staging workflows, environment configuration, and CI/CD patterns. Use when deploying WooCommerce stores or setting up deployment pipelines.
spree-deployment
Deploy Spree to production — PostgreSQL + Redis + Sidekiq stack, Docker multi-arch images on GHCR, the `spree-starter` Dockerfile + Compose, Heroku/Render/Fly.io/AWS targets, env-var conventions, RAILS_MASTER_KEY, asset precompilation (Tailwind 4 + Propshaft), Action Cable, MeiliSearch indexing, S3 / ActiveStorage for media, log/observability setup, zero-downtime deploys, and migration strategy. Use when going from local dev to production, scaling Spree, or troubleshooting deploys.
saleor-deploy
Deploy Saleor to production — Docker setup, Saleor Cloud, environment variables, Celery workers, S3 media storage, database management, and scaling. Use when deploying Saleor applications.
medusa-workflows
Build Medusa v2 workflows — steps with createStep, compensation/rollback, parallel execution, hooks for extending built-in workflows, and when conditions. Use when orchestrating multi-step operations.
medusa-testing
Test Medusa v2 applications — Jest setup, module unit tests, workflow integration tests, API route tests, medusaIntegrationTestRunner, and mock patterns. Use when writing tests for Medusa projects.
medusa-subscribers
Implement Medusa v2 event subscribers — pub/sub event handling, subscriber handler functions, scheduled jobs with cron, and the event module (Redis or in-memory). Use when reacting to commerce events.
medusa-storefront
Build Medusa v2 storefronts with Next.js 15 — App Router, JS SDK client setup, Tanstack Query, server components, product pages, cart, and checkout flow. Use when developing headless storefronts.
medusa-setup
Set up a Medusa v2 development environment — CLI, PostgreSQL/Redis prerequisites, project creation, medusa-config.ts, directory structure, environment variables. Use when starting a new Medusa project.
medusa-security
Secure Medusa v2 applications — authentication strategies, API key types (publishable vs secret), CORS configuration, JWT and cookie secrets, admin vs store auth, and session management. Use when configuring security.
medusa-pricing
Configure Medusa v2 pricing — pricing module, price lists with rules, currencies, tax calculation, regions, and promotion campaigns. Use when setting up pricing and discounts.
medusa-plugins
Develop and publish Medusa v2 plugins — plugin structure, plugin vs module comparison, npm packaging, and reusable plugin template. Use when building distributable Medusa extensions.
medusa-payments
Implement Medusa v2 payment processing — payment module, provider abstraction, payment sessions, authorization/capture/refund lifecycle, and Stripe/PayPal integration. Use when adding payment providers.