GuideRAILWAYBeginner

Deploying Medusa backend using Railway

This guide describes how to set up and deploy a Medusa backend using Railway with managed PostgreSQL and Redis databases.

Prerequisites

Before you begin, make sure you have the following:

  • Railway account
  • GitHub account connected with Railway
  • Git installed on your local machine

1. Create Project with Database Services

  • Log in to Railway and click Create New Project → Empty Project.

PostgreSQL Configuration

  • In your Railway project dashboard, click Create.
  • Select Database → Add PostgreSQL.
  • Railway will automatically create a PostgreSQL instance.

Redis Configuration

  • In your Railway project dashboard, click Create.
  • Select Database → Add Redis.
  • Railway will automatically create a Redis instance.

2. Prepare the Medusa Project

  • Clone your MedusaJS project to your server. This guide assumes your repository has a backend directory and a storefront directory at the root level:

    git clone <your-medusa-repository-url>
    cd your-medusa-project
    
  • Download the Medusa configuration file using curl:

    curl -O https://raw.githubusercontent.com/u11d-com/medusa-starter/main/backend/medusa-config.ts
    
  • Download the startup script using curl:

    curl -O https://raw.githubusercontent.com/u11d-com/medusa-starter/main/backend/start.sh
    
  • Make the startup script executable:

    chmod +x start.sh
    
  • Modify the package.json file to update the start command only:

      {
        "scripts": {
          "start": "./start.sh"
        }
      }
    
  • Add new file railway.json with content as below:

    {
      "$schema": "https://railway.app/railway.schema.json",
      "build": {
        "builder": "NIXPACKS",
        "buildCommand": "yarn build"
      },
      "deploy": {
        "startCommand": "yarn run start",
        "healthcheckPath": "/health",
        "restartPolicyType": "ON_FAILURE",
        "restartPolicyMaxRetries": 10
      }
    }
    
  • Commit and push your changes to GitHub.

3. Deploy on Railway

  • In your Railway project dashboard, click Create.
  • Select GitHub Repository.
  • If you don’t see any repositories connect your GitHub account.
  • Select the repository you forked.
  • Railway will automatically detect your Node.js project and begin the initial deployment.
  • Fulfill environments in your server instance:
    • REDIS_URL with a value from REDIS_URL
    • CACHE_REDIS_URL with a value from REDIS_URL
    • WE_REDIS_URL with a value from REDIS_URL
    • EVENT_REDIS_URL with a value from REDIS_URL
    • DB_NAME with a value from PG_DATABASE
    • DB_HOST with a value from PG_HOST
    • MEDUSA_CREATE_ADMIN_USER with true
    • MEDUSA_ADMIN_EMAIL with your admin user email address
    • MEDUSA_ADMIN_PASSWORD with your admin user password
  • Click Deploy button (you should see it in the up of the canvas).
  • Wait for the build process to complete. This may take several minutes.
  • Once deployed, your server should be available at port 8080.

5. Configure networking

  • Go to the server settings.

  • Scroll down to networking, and click Generate Domain button under Public Networking.

  • Copy your generated domain, and check if the backend is health:

      https://<your-app>.up.railway.app/health
    

    You should receive a healthy response if everything is set up correctly.

Summary

You have now deployed a MedusaJS backend on Railway using managed PostgreSQL and Redis services. Your environment is configured for production with an optional admin user creation process and accessible admin panel at the /app path.

Planning an integration, storefront, migration, or operational improvement?

Tell us what needs to change and we'll respond within 24 hours with a straight assessment — including whether the work is a fit. Or start with the open-source packages we maintain and the deployment guides we publish.

Development, integrations, deployment, and ongoing support — scoped in writing.

Get in Touch
Tell us about your project and we'll respond within 24 hours with next steps.
What do you need?
Platforms of Interest

By submitting this form, you agree to our Privacy Policy and Terms of Service.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.