I Cut My Rails Hosting Costs by 70%: Migrating from Heroku to Railway

Published: (March 8, 2026 at 10:59 AM EDT)
5 min read
Source: Dev.to

Source: Dev.to

TL;DR

I migrated a Rails API from Heroku + JawsDB to Railway.

Results

MetricBeforeAfter
Hosting cost~​$20 / month~​$6 / month
Migration time~​20–30 minutes
DowntimeNoneNone
Database migrationOne streaming command

My Original Setup

Rails API

Heroku Dyno

JawsDB (MySQL)

Approximate monthly cost

ServiceProviderCost
App hostingHeroku~$7–10
MySQLJawsDB~$10–12
Total~$20/month

Not huge, but for side projects I prefer keeping infrastructure simple and inexpensive.

The New Setup

Rails API

Railway App

Railway MySQL

New cost breakdown

ServiceProviderCost
App hostingRailway~$3–4
MySQLRailway~$2
Total~$6/month

That’s roughly a 70 % cost reduction.

Migration Strategy

The migration consisted of four steps:

  1. Link the Railway project
  2. Export the database from JawsDB
  3. Import the data into Railway MySQL
  4. Update the Rails configuration

No downtime was required.

  1. Install and authenticate with the Railway CLI.
  2. Run:
railway link

What this does

  • Connects your local repo to your Railway project
  • Allows the CLI to run commands against that project
  • Creates a .railway folder locally

This step only needs to be done once per repository.

Step 2: Dump Data from JawsDB and Import into Railway

Instead of creating a dump file and importing it later, you can stream the database directly.

mysqldump \
  -h [jawsdb-host] \
  -u [jawsdb-user] \
  -p[jawsdb-password] \
  --no-tablespaces \
  --set-gtid-purged=OFF \
  --single-transaction \
  [jawsdb-database] \
| railway run -s MySQL mysql \
  -h $MYSQLHOST \
  -u $MYSQLUSER \
  -p$MYSQLPASSWORD \
  $MYSQLDATABASE

What this does

  • Exports the database from JawsDB
  • Pipes the output directly into Railway MySQL

Why These Flags Matter

FlagReason
--no-tablespacesJawsDB runs on AWS RDS, which restricts privileges needed for dumping tablespaces.
--set-gtid-purged=OFFPrevents replication metadata from causing conflicts during import.
--single-transactionCreates a consistent snapshot of the database while exporting (ideal for InnoDB tables).

Why Streaming the Database Is Powerful

The pipe (|) streams the SQL output directly into Railway:

JawsDB → mysqldump → pipe → Railway MySQL

Benefits

  • No intermediate dump files
  • Faster migration
  • Lower disk usage
  • Works well for large databases

Step 3: Verify the Migration

After the import, verify the migration with:

railway run -s MySQL mysql \
  -h $MYSQLHOST \
  -u $MYSQLUSER \
  -p$MYSQLPASSWORD \
  $MYSQLDATABASE \
  -e "SHOW TABLES;"

You should see your tables, e.g.:

users
transactions
posts
comments

Step 4: Update Rails Configuration

Previously, the Rails app used the JawsDB DATABASE_URL. Railway automatically provides environment variables:

MYSQLHOST
MYSQLPORT
MYSQLUSER
MYSQLPASSWORD
MYSQLDATABASE
MYSQL_URL

The simplest Rails configuration is:

production:
  adapter: mysql2
  url:

After pushing the code, Railway automatically redeployed the application.

Heroku vs Railway (Quick Comparison)

FeatureHeroku + JawsDBRailway
Hosting modelApp dynos + add‑onsApp + services in one platform
DatabaseJawsDB MySQL add‑onNative managed MySQL
Cost (small project)~​$20 / month~​$6 / month
DeploymentGit pushGit push (auto‑redeploy)

Bottom line: By moving a small Rails API from Heroku + JawsDB to Railway, I cut my monthly hosting bill by about 70 % and completed the migration in under 30 minutes with zero downtime. 🚀

Git push / GitHub integration

FeatureHerokuRailway
Environment variablesSupportedSupported
CLI toolsHeroku CLIRailway CLI
Database migrationManual dump / importEasy via railway run
Infrastructure managementManagedManaged
Static outbound IPNot guaranteedNot guaranteed
Best suited forMature production appsSide projects & small apps

Final Thoughts

Heroku still offers one of the best developer experiences.

But for small projects or side tools, simplifying infrastructure and reducing costs can make sense.

For my Rails API, moving to Railway gave me:

  • a simplified stack
  • hosting costs reduced by ~70%
  • minimal migration effort

If you’re running a small Rails project with MySQL on Heroku, exploring Railway might be worth considering.

Question for Other Developers

If you’re hosting side projects:

  • Are you still using Heroku?
  • Or have you moved to platforms like Railway, Fly.io, or Render?

I’d love to hear what your stack looks like.

0 views
Back to Blog

Related posts

Read more »