I Cut My Rails Hosting Costs by 70%: Migrating from Heroku to Railway
Source: Dev.to
TL;DR
I migrated a Rails API from Heroku + JawsDB to Railway.
Results
| Metric | Before | After |
|---|---|---|
| Hosting cost | ~$20 / month | ~$6 / month |
| Migration time | — | ~20–30 minutes |
| Downtime | None | None |
| Database migration | One streaming command | — |
My Original Setup
Rails API
│
Heroku Dyno
│
JawsDB (MySQL)
Approximate monthly cost
| Service | Provider | Cost |
|---|---|---|
| App hosting | Heroku | ~$7–10 |
| MySQL | JawsDB | ~$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
| Service | Provider | Cost |
|---|---|---|
| App hosting | Railway | ~$3–4 |
| MySQL | Railway | ~$2 |
| Total | — | ~$6/month |
That’s roughly a 70 % cost reduction.
Migration Strategy
The migration consisted of four steps:
- Link the Railway project
- Export the database from JawsDB
- Import the data into Railway MySQL
- Update the Rails configuration
No downtime was required.
Step 1: Link Your Railway Project
- Install and authenticate with the Railway CLI.
- 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
.railwayfolder 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
| Flag | Reason |
|---|---|
--no-tablespaces | JawsDB runs on AWS RDS, which restricts privileges needed for dumping tablespaces. |
--set-gtid-purged=OFF | Prevents replication metadata from causing conflicts during import. |
--single-transaction | Creates 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)
| Feature | Heroku + JawsDB | Railway |
|---|---|---|
| Hosting model | App dynos + add‑ons | App + services in one platform |
| Database | JawsDB MySQL add‑on | Native managed MySQL |
| Cost (small project) | ~$20 / month | ~$6 / month |
| Deployment | Git push | Git 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
| Feature | Heroku | Railway |
|---|---|---|
| Environment variables | Supported | Supported |
| CLI tools | Heroku CLI | Railway CLI |
| Database migration | Manual dump / import | Easy via railway run |
| Infrastructure management | Managed | Managed |
| Static outbound IP | Not guaranteed | Not guaranteed |
| Best suited for | Mature production apps | Side 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.