> ## Documentation Index
> Fetch the complete documentation index at: https://docs.shardcloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Migrate from Railway to Shard Cloud

> Move a Railway project (services, variables, databases, volumes and cron services) to Shard Cloud, step by step.

## Introduction

This guide moves a Railway project to Shard Cloud. Each Railway service becomes a Shard Cloud project:

| On Railway | On Shard Cloud |
| - | - |
| Service from a GitHub repo (Railpack/Nixpacks build) | An [application](https://docs.shardcloud.app/apps.md) |
| Service from a `Dockerfile` | An application from a [custom Docker image](https://docs.shardcloud.app/custom-docker-images.md) (Core plan and above) |
| Public domain (`*.up.railway.app`) | The app's `SUBDOMAIN` (`*.shardweb.app`) |
| Service without a public domain (worker) | An application without a subdomain |
| Pre-deploy command | A command that runs before your app starts |
| Cron schedule | A small application that runs the job on a timer |
| Variables and reference variables | Environment variables (import a `.env` file) |
| PostgreSQL, MySQL, MongoDB, Redis | A managed [database](https://docs.shardcloud.app/databases.md) of the same type |
| Volume | The app's persistent `/app` folder |
| Replicas | Copies of the app behind a load balancer (Pro plan and above) |
| Custom domain | [Custom domain](https://docs.shardcloud.app/tutorials/platform/custom-domain.md), with HTTPS included |

Things that stay the same:

* **`PORT` keeps working.** Railway tells your app which port to use through `PORT`, and so does Shard Cloud: every container sets `PORT=80`. An app that listens on `process.env.PORT` (or `os.environ["PORT"]`) on `0.0.0.0` needs no change.
* **Always on.** Apps run all the time, with no sleeping, and restart automatically if they crash.

> [!WARNING]
>
> **Services can't talk over a private network.** On Railway, services reach each other at `<service>.railway.internal` on any port. On Shard Cloud, an application reaches another application only through its public address (`https://other-app.shardweb.app` or its domain), and only over HTTP on port 80. Databases are different: apps reach them through their connection URL, over Shard Cloud's private network. A service that needs other ports (a game server, a message broker such as RabbitMQ, anything behind a Railway TCP proxy) belongs on a [VPS](https://docs.shardcloud.app/vps.md).

## Before You Start

### What you need

* The [Railway CLI](https://docs.railway.com/guides/cli), logged in (`railway login`) and linked to the project (`railway link` in the code folder)
* The code of each service
* A Shard Cloud account with room for every service and database (see the minimum RAM of each on the [limits page](https://docs.shardcloud.app/limits.md))
* To copy databases: [Docker](https://www.docker.com/), or the database's own tools installed locally

### Take stock of the project

Open the project canvas on Railway and note, for each service:

* Its source (repository and root directory, or `Dockerfile`), and whether it has a public domain
* Its **Custom Build Command**, **Pre-deploy Command**, **Custom Start Command** and **Cron Schedule** (in the service's **Settings**, or in `railway.json` / `railway.toml`)
* Any **volume** and its mount path
* Which services call each other through `.railway.internal` addresses

## Step 1: Export the Variables

For each service, print its variables with references already resolved:

```bash theme={null}
railway variables --service YOUR_SERVICE --kv > your-service.env
```

Open each file and:

* **Delete the ones Railway adds**: every `RAILWAY_*` variable (`RAILWAY_PUBLIC_DOMAIN`, `RAILWAY_PRIVATE_DOMAIN`, `RAILWAY_ENVIRONMENT`...).
* **Delete the database URLs** (`DATABASE_URL`, `REDIS_URL`, `MONGO_URL`, `MYSQL_URL`...): you'll set them to the new databases in step 4.
* **Replace `.railway.internal` addresses** with the other app's Shard Cloud address, `https://other-app.shardweb.app` (see the warning above).

> [!WARNING]
>
> These files contain your secrets. Don't commit them, and delete them when you're done.

## Step 2: Create the Databases

In the [Dashboard](https://shardcloud.app/dash), create a database for each one on Railway, of the same type. Pick the same version as on Railway or a newer one: the version can't change later. Each database's page shows its connection URL, which you'll use in steps 3 and 4.

## Step 3: Move the Data

Railway databases accept outside connections through their **public** URL: `DATABASE_PUBLIC_URL`, `MYSQL_PUBLIC_URL`, `MONGO_PUBLIC_URL` or `REDIS_PUBLIC_URL` in the database service's variables. The non-public URLs only work inside Railway.

> [!TIP]
>
> To keep the data consistent, stop the services that write to the database before you copy it. Writes made after the dump won't be copied.

> [tab] PostgreSQL
>
> Dump with `pg_dump` and restore with `pg_restore`, using the Docker image of your Shard Cloud database's major version (`postgres:17`, `postgres:18`):
>
> ```bash theme={null}
> docker run --rm -v "$PWD:/backup" postgres:17 \
>   pg_dump -Fc --no-owner --no-acl -f /backup/railway.dump "YOUR_DATABASE_PUBLIC_URL"
>
> docker run --rm -v "$PWD:/backup" postgres:17 \
>   pg_restore --verbose --no-owner --no-acl \
>   --dbname "YOUR_SHARD_CLOUD_DATABASE_URL" /backup/railway.dump
> ```
>
> Then check that your tables and their row counts are all there:
>
> ```bash theme={null}
> psql "YOUR_SHARD_CLOUD_DATABASE_URL" -c "\dt+"
> ```

> [tab] MySQL
>
> Take the host, port, user, password and database from `MYSQL_PUBLIC_URL` (`mysql://USER:PASSWORD@HOST:PORT/DATABASE`) and from your Shard Cloud database's page:
>
> ```bash theme={null}
> mysqldump --single-transaction --routines --triggers -h OLD_HOST -P OLD_PORT -u OLD_USER -p OLD_DB > dump.sql
> mysql -h NEW_HOST -P NEW_PORT -u NEW_USER -p NEW_DB < dump.sql
> ```

> [tab] MongoDB
>
> ```bash theme={null}
> mongodump --uri "YOUR_MONGO_PUBLIC_URL" --archive=dump.archive --gzip
> mongorestore --uri "YOUR_SHARD_CLOUD_MONGODB_URL" --archive=dump.archive --gzip
> ```

> [tab] Redis
>
> If Redis is a cache or a job queue, there's nothing to copy: it starts empty.
>
> If it holds data you need, copy the keys with this script. Use a Shard Cloud Redis of the same version as Railway's or newer, since a key dumped by a newer Redis can't be restored into an older one:
>
> ```javascript copy-redis.js theme={null}
> // npm install ioredis
> // OLD_REDIS_URL=... NEW_REDIS_URL=... node copy-redis.js
> const Redis = require('ioredis');
>
> const from = new Redis(process.env.OLD_REDIS_URL);
> const to = new Redis(process.env.NEW_REDIS_URL);
>
> (async () => {
>   let cursor = '0';
>   let copied = 0;
>   do {
>     const [next, keys] = await from.scan(cursor, 'COUNT', 500);
>     cursor = next;
>     for (const key of keys) {
>       const value = await from.dumpBuffer(key);
>       if (!value) continue; // expired meanwhile
>       const ttl = await from.pttl(key);
>       await to.restore(key, ttl > 0 ? ttl : 0, value, 'REPLACE');
>       copied++;
>     }
>   } while (cursor !== '0');
>   console.log(`Copied ${copied} keys`);
>   process.exit(0);
> })();
> ```

## Step 4: Set the Environment Variables

Add the new databases' URLs to each service's `.env` file, under the names its code reads:

```bash your-service.env theme={null}
DATABASE_URL=YOUR_SHARD_CLOUD_DATABASE_URL
REDIS_URL=YOUR_SHARD_CLOUD_REDIS_URL
```

You'll import each file into its application in step 7.

> [!NOTE]
>
> Shard Cloud databases only accept encrypted connections. Most drivers handle this with the connection URL alone; if yours connects without TLS by default, turn it on (for example `ssl: { rejectUnauthorized: false }` in Node's `pg`, or `sslmode=require`).

## Step 5: Translate Each Service

Each service becomes one application, configured by a [`.shardcloud`](https://docs.shardcloud.app/config) file. Railway builds your app (Railpack or Nixpacks run `npm run build` and the like) before starting it; Shard Cloud installs the dependencies but doesn't run a build, so put the build in the start command. A **pre-deploy command** (usually migrations) goes in front of it, so it runs each time the app starts.

> [tab] Node.js
>
> A service with the pre-deploy command `npx prisma migrate deploy` and the start command `npm start` becomes:
>
> ```systemd .shardcloud theme={null}
> DISPLAY_NAME=My API
> LANGUAGE=node
> MEMORY=512
> VERSION=recommended
> SUBDOMAIN=myapi
> CUSTOM_COMMAND=npx prisma migrate deploy && npm run build && npm start
> ```
>
> Drop `npm run build` if `package.json` has no `build` script. Dependencies are installed with npm, yarn, pnpm or bun, following your lockfile. Set `VERSION` to your Node.js major version (the `engines` field, or `.nvmrc`) if it isn't the recommended one.

> [tab] Python
>
> ```systemd .shardcloud theme={null}
> DISPLAY_NAME=My API
> LANGUAGE=python
> MEMORY=512
> VERSION=recommended
> SUBDOMAIN=myapi
> CUSTOM_COMMAND=python manage.py migrate && python -m gunicorn myproject.wsgi
> ```
>
> > [!WARNING]
> >
> > Run Python tools as modules: `python -m gunicorn`, `python -m uvicorn main:app --host 0.0.0.0 --port 80`, `python -m celery`. Packages from `requirements.txt` are installed where Python finds them, but their command-line scripts aren't on the `PATH`, so a bare `gunicorn` isn't found.
>
> Gunicorn listens on `0.0.0.0:$PORT` by itself. Dependencies are installed from `requirements.txt`: if your project only has `pyproject.toml` or a Pipfile, export a `requirements.txt` first (for example `uv export --no-hashes > requirements.txt` or `poetry export -f requirements.txt --without-hashes > requirements.txt`). Set `VERSION` to your Python version if it isn't the recommended one.

> [tab] Dockerfile
>
> A service Railway builds from a `Dockerfile` moves as a [custom Docker image](https://docs.shardcloud.app/custom-docker-images.md): upload the code (with the `Dockerfile` at the root) as an image, then create an application from it. If the service receives web traffic, give the app a subdomain and make sure the server listens on port 80 on `0.0.0.0`. Custom images need the Core plan or above.

> [tab] Static site
>
> A site Railway builds to static files and serves with Caddy runs with a small server that sends every unknown route to `index.html`:
>
> ```systemd .shardcloud theme={null}
> DISPLAY_NAME=My Site
> LANGUAGE=node
> MEMORY=512
> VERSION=recommended
> SUBDOMAIN=mysite
> CUSTOM_COMMAND=npm run build && npx serve -s dist -l 80
> ```
>
> Replace `dist` with your framework's output folder.

For other languages, see the guide for your language: [Go](https://docs.shardcloud.app/languages/go.md), [Ruby](https://docs.shardcloud.app/languages/ruby.md), [PHP](https://docs.shardcloud.app/languages/php.md), [Java](https://docs.shardcloud.app/languages/java.md), [Elixir](https://docs.shardcloud.app/languages/elixir.md) or [C#](https://docs.shardcloud.app/languages/csharp.md).

### Workers

A service with no public domain (a queue worker, a bot) is an application **without** `SUBDOMAIN`, so it needs only 256 MB:

```systemd .shardcloud theme={null}
DISPLAY_NAME=My Worker
LANGUAGE=node
MEMORY=256
VERSION=recommended
CUSTOM_COMMAND=node worker.js
```

### Cron services

On Railway, a service with a **Cron Schedule** starts on the schedule, runs, and exits. Shard Cloud has no job scheduler of its own: run the job from a small, always-on application with a scheduling library such as [node-cron](https://www.npmjs.com/package/node-cron) (or [APScheduler](https://apscheduler.readthedocs.io/) for Python), using the same schedule. Railway's cron schedules are in UTC:

```javascript scheduler.js theme={null}
const cron = require('node-cron');
const { execSync } = require('child_process');

// The service's Cron Schedule and its start command
cron.schedule('0 3 * * *', () => {
  execSync('node jobs/cleanup.js', { stdio: 'inherit' });
}, { timezone: 'UTC' });
```

### Volumes

Each application has a persistent `/app` folder (the code's own folder; see the size on the [limits page](https://docs.shardcloud.app/limits.md)) whose files survive restarts and deploys. A Railway volume mounted at another path (such as `/data`) becomes a folder inside the app: point your code at it, for example `DATA_DIR=/app/data`.

To bring the files over, copy them out of the Railway service (for example with `railway ssh` into the service and `tar`, if its image has them), then upload them to the application with its file manager in the dashboard, or include them in the ZIP.

### Monorepos

On Railway, a service can build from a subfolder of the repository (its **Root Directory**). On Shard Cloud, an application's files are the whole upload: zip each service's folder on its own, with its `.shardcloud` at the root of the ZIP.

## Step 6: Replicas (Optional)

Railway's replicas become copies of the application: create the same app more than once and put the copies behind a load balancer (Pro plan and above), which splits the traffic between them and skips a copy that is down.

## Step 7: Deploy

**1. Upload each application**

Zip each service's code with its `.shardcloud` at the root, **without** `node_modules/`, virtualenvs or build output (100 MB at most), and upload it in the [Dashboard](https://shardcloud.app/dash/applications).

**2. Import the environment variables**

On each application's page, open **Environment Variables**, choose **Import .env** and pick that service's file. Check the values, then restart the application.

**3. Connect GitHub (optional)**

To deploy on every push, like Railway does, connect each application to its repository and branch on its **Deploy** page, and turn on **Auto-Restart on Deploy**. See [Git integration](https://docs.shardcloud.app/tutorials/platform/git-integration.md).

> [!WARNING]
>
> A `.shardcloud` file in your repository is applied to **every** application deployed from it. With several applications on the same repository (a monorepo, or an API and a worker), keep `.shardcloud` out of the repository (add it to `.gitignore`) and let each application keep the one it was uploaded with.

## Step 8: Test, Then Switch the Domain

**1. Test on the free subdomain**

Open `https://myapi.shardweb.app` and check the pages and routes that read and write data. Check the workers' logs on their pages, and that services that used to call each other privately now reach each other through their public addresses.

**2. Add your domain**

Add your domain to the application and point its DNS at Shard Cloud, replacing Railway's CNAME. See [Custom Domain](https://docs.shardcloud.app/tutorials/platform/custom-domain.md). HTTPS is set up for you.

**3. Shut down Railway**

Once traffic is on Shard Cloud and you've checked the data, remove the services on Railway. Keep the Railway databases until you're sure nothing is missing, then delete them, and their volumes, to stop the charges.

## Troubleshooting

> [accordion] The app starts but the site doesn't load
>
> The server must listen on `0.0.0.0` and on `$PORT` (80). A hardcoded port, or listening on `localhost` only, makes the site unreachable.

> [accordion] A service can't reach another one
>
> `.railway.internal` addresses don't exist on Shard Cloud. Use the other application's public address (`https://other-app.shardweb.app`). Only HTTP on port 80 is reachable; other ports need a VPS.

> [accordion] gunicorn: not found (or uvicorn, celery)
>
> Use `python -m gunicorn` (or `python -m uvicorn`, `python -m celery`) in `CUSTOM_COMMAND`.

> [accordion] Out of memory during the build
>
> The build runs when the app starts, inside the app's RAM. Raise `MEMORY` (1024 MB is a safe start for frontend builds) or build locally and upload the built files.

> [accordion] Can't connect to the Railway database to dump it
>
> Use the database's **public** URL (`DATABASE_PUBLIC_URL` and similar). The private URL only works from inside Railway.

> [accordion] Changed an environment variable and nothing happened
>
> Environment variables are read when the app starts: restart the application after changing them.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.