Guide

How to host multiple Rails apps on one server

The cheapest way to run several Rails apps is one server with one proxy that routes by domain, one Postgres with a database per app, and a Puma process for each app. Here's how to lay it out, how much memory it takes, and when to split apps onto their own servers.

Platforms charge per app, so a handful of side projects, client sites, or internal tools can cost more than the work they do. A single 4–8GB server runs most of those together for the price of the server.

How the server is laid out

One proxy, routing by domain

Caddy or Nginx listens on ports 80 and 443 and forwards each domain to the right app. Each app's Puma listens on its own local port or Unix socket. Caddy gets an SSL certificate for every domain on its own.

One Postgres, a database per app

Run a single Postgres server and give each app its own database and its own database user, so one app can't read another's data. One Postgres uses far less memory than one per app.

Separate processes and environments

Each app gets its own directory, environment variables, Puma process, and job worker, supervised by systemd. A crash or a deploy in one app doesn't touch the others.

Ruby versions side by side

A version manager (rbenv, asdf, or mise) lets one app stay on an older Ruby while another uses the latest, each reading its own .ruby-version.

How many apps fit on one server

Memory runs out before CPU does. Rough figures for a typical app:

  • Puma: 200–400MB for a single process, more with several workers.
  • Job worker: another 200–400MB. Solid Queue can run inside Puma to save one process per app.
  • Postgres: shared by every app. Budget 500MB–1GB for small databases.
  • Redis: one shared instance, if any app uses Sidekiq. Give each app its own database number or key prefix.

That puts 3–5 low-traffic apps on a 4GB server and 8–10 on 8GB. Watch memory after each new app, and move the busiest app to its own server when it starts to crowd the others.

Setting it up yourself

With Caddy, each app is a few lines in the Caddyfile. Puma for each app binds to its own port:

app-one.com {
  reverse_proxy 127.0.0.1:3001
}

app-two.com {
  reverse_proxy 127.0.0.1:3002
}

Then, for each app:

  1. Create a Postgres user and database for it, and set its DATABASE_URL.
  2. Put its code in its own directory, with its own environment file holding PORT, RAILS_MASTER_KEY, and the rest.
  3. Write systemd units for its Puma and job worker that read that environment file.
  4. Give it its own deploy script or Capistrano config pointing at that directory.

Kamal can also put several apps on one host. Each app has its own config/deploy.yml with a different proxy host, and one kamal-proxy routes between them. Share a single Postgres accessory between apps, or give each app its own on a different port.

With Hatchbox

Hatchbox charges per server, not per app, so the second through tenth apps on a server cost nothing extra. Create each app from its repository on the same cluster and Hatchbox gives it:

  • Its own directory, port, environment variables, and supervised processes.
  • Its own Postgres or MySQL database and database user, on the shared database server.
  • Its own domains in Caddy, each with an automatic SSL certificate.
  • The Ruby version from its own .ruby-version.
  • Its own deploys, logs, and cron jobs, independent of the other apps.

When one app outgrows the shared server, create a cluster for it, deploy it there, and copy its database across. The other apps don't change.

Multiple Rails apps on one server: questions

Still stuck? Ask us directly — a real person who runs a lot of Rails apps side by side will answer.

What's the cheapest way to host multiple Rails apps?

One VPS with a shared reverse proxy, a shared Postgres server, and a Puma process per app. A 4GB server from Hetzner, OVHcloud, or DigitalOcean runs several low-traffic apps for the price of the server alone. Platforms that bill per app get expensive with more than one or two.

Can two Rails apps share one Postgres database server?

Yes. Give each app its own database and its own database user on the same Postgres server. They share memory and disk, but they can't read each other's data.

Can apps on the same server use different Ruby versions?

Yes. A Ruby version manager installs several versions side by side, and each app uses the one in its .ruby-version file. Hatchbox does this for you on every deploy.

Can Kamal deploy multiple apps to one server?

Yes. Since Kamal 2, kamal-proxy routes requests to different apps by hostname. Each app keeps its own config/deploy.yml.

How much does Hatchbox cost for multiple apps?

$15 per server per month, with unlimited apps on each server. Five apps on one server cost the same $15 as one app.

When should an app move to its own server?

When its traffic or background jobs slow down the other apps, or it needs to restart or scale on its own schedule. Until then, sharing a server is the cheapest option.

Simple, predictable pricing.

We charge per server, not per app. Run one application or twenty on the same box — the bill doesn't change.

Start free trial

$15

/server/mo
  • Unlimited applications
  • Deploy anywhere
  • Zero downtime deployments
  • Custom domains & free SSL
  • Databases, cron jobs & background workers
  • Full SSH access to your servers
  • Real, human support
  • 7 day free trial

Ready to deploy your Rails app?

Hatchbox has run more than 2 million deploys across 24,000+ applications since 2016. Start a 7 day free trial and put yours on a server you own.