Deploy FastAPI with Postgres to your own server.
Ployz builds your FastAPI app from GitHub on a server you rent, runs it with Uvicorn behind HTTPS, adds Postgres in one click and runs alembic upgrade head before every deploy. Every pull request gets its own preview, your coding agent can run all of it, and deleting a database waits for you.
One FastAPI app with Postgres, five bills.
An always-on web app with Postgres costs about $14 a month on Railway when it's small, $62 at a medium size and $218 when it's busy. The same three apps run on one rented Hetzner server for $7, $11 and $19, and Ployz is free on it, custom domains included.
| Small | Medium | Busy | |
|---|---|---|---|
| Railway (usage) | $14 | $62 | $218 |
| Your own server + Ployz | $7 (CX23, 4 GB) | $11 (CX33, 8 GB) | $19 (CX43, 16 GB) |
On the fixed-price platforms the floor is a web service plus a database: Heroku's always-on Basic dyno is $7 and a database adds $5 or more, Render's web service starts at $7 and Postgres at $6 plus storage, and Fly.io's Managed Postgres starts at $38 on its own. The apps and every source are in Railway pricing, Heroku pricing, Render pricing and Fly.io pricing. Server prices are Hetzner's in Europe; for the US, see Hetzner vs DigitalOcean.
How to deploy FastAPI with Postgres to your own server.
A FastAPI app in production is Uvicorn serving your app behind an HTTPS proxy, a Postgres database, and migrations that run once before the new code takes traffic. Ployz runs each of those on your server, built from your repository with no Dockerfile.
$ curl -fsSL https://ployz.sh | sh
Installs the ployz CLI on macOS or Linux.
$ ployz login
Signs in to Ployz Cloud in your browser.
$ ployz up --server root@your-server
Installs Ployz on the server, builds this directory and gives it an HTTPS address.
Or paste Read ployz.dev/agents.md and deploy this repo to my server. into Claude Code, Codex or Cursor and it runs these steps for you. Then finish the app in the dashboard:
- Rent a server. Any provider works. Pick Ubuntu LTS with 2 GB of RAM or more, since builds run on the server too; 4 GB leaves room for Postgres.
- Connect GitHub so every push deploys: add the repository as a service (Deploy from GitHub).
- Check the start command. With
main.pyat the root anduvicornin your dependencies, Railpack startsuvicorn main:appon the right port. For any other layout, set the start command tofastapi run app/main.py --port $PORT, with your own path. - Add Postgres. Click Create, then Database, then PostgreSQL.
- Connect the app. Add a variable
DATABASE_URLwith the value${{ postgres.DATABASE_URL }}. It points at Postgres over your servers' private network. - Run migrations before each deploy. Set the pre-deploy command to
alembic upgrade head. - Set the health check to a route that returns 200, like a
/healthendpoint, so a new version must answer before the old one stops. - Point your domain at the server, or keep the generated HTTPS address.
From then on, git push builds and deploys, and every pull request gets its own preview. Give previews their own Postgres and each one starts empty; a setup command can seed it.
What Railpack does with a FastAPI app.
Ployz builds with Railpack, so you don't need a Dockerfile:
- It finds Python from
requirements.txt,pyproject.tomlor aPipfile, and installs with pip, Poetry, PDM, uv or Pipenv, whichever your lockfile says. - It finds FastAPI when
fastapiis a dependency. Ifmain.pyis at the root anduvicornis listed too, it startsuvicorn main:app --host 0.0.0.0 --port ${PORT:-8000}. Ployz setsPORTto 8080, and your domain sends traffic there. - Otherwise, set the start command.
fastapi[standard]brings Uvicorn without naming it in your dependency file, and many apps live inapp/main.py. FastAPI's own docs start it withfastapi run app/main.py, which "uses Uvicorn underneath" and listens on0.0.0.0. On a Railpack build the start command runs in a shell, so--port $PORTworks.
Your own Dockerfile works too: set Build method to Dockerfile, and keep FastAPI's advice to use the exec form of CMD "to ensure that FastAPI can shutdown gracefully and lifespan events are triggered".
Workers: replicas, not --workers. FastAPI's deployment docs say that when something else handles replication, you "would want to have just a single Uvicorn process per container (but probably multiple containers)". On Ployz that's the replica count: run one Uvicorn process per replica and add replicas, up to 50 per service, spread across your servers. On one small server, --workers 2 is fine too, as long as the processes fit in memory.
Why migrations go in the pre-deploy command. FastAPI's docs say migrations belong in a separate step that runs once "before running the replicated worker containers", not in each one. The pre-deploy command is that step: it runs once with the new code before any replica is replaced, and if it fails, the deploy stops and the old version keeps serving.
Which Postgres driver? The DATABASE_URL Ployz gives you starts with postgresql://, which SQLAlchemy reads as psycopg2. For psycopg 3 or asyncpg, build the URL from the database's own variables: postgresql+asyncpg://${{ postgres.PGUSER }}:${{ postgres.PGPASSWORD }}@${{ postgres.PGHOST }}:${{ postgres.PGPORT }}/${{ postgres.PGDATABASE }}. Have Alembic's env.py read the same variable, so migrations and the app use one database.
Background jobs. FastAPI's BackgroundTasks run in the web process. For heavy or long jobs, add Redis in one click and a second service from the same repository whose start command runs your worker, like celery -A app.worker worker.
Ployz and the hosted platforms.
| What you need | Heroku, Render, Railway, Fly.io | Ployz on your server |
|---|---|---|
| Builds | Buildpacks, Railpack or your Dockerfile, depending on the platform | No Dockerfile needed for Python (pip, Poetry, PDM, uv and Pipenv), or bring your own Dockerfile |
| Web process | A dyno, service or Machine, each with its own price | A service running Uvicorn, with as many replicas as you pick, sharing the server's RAM |
| Postgres | Managed add-ons, from $5 to $38 for the smallest | One-click Postgres on your server, with a restore point |
| Migrations | Release phase, pre-deploy or release command | A pre-deploy command, `alembic upgrade head`, runs once before each deploy |
| Previews per PR | Review apps or PR environments, billed per service; Render needs Pro, Fly has none built in | A preview environment for every pull request, with its own HTTPS address, on your servers. A Postgres it copies starts empty |
| Zero-downtime deploys | Yes, on most plans | With a health check set, the new version must pass it before the old one stops. Postgres has a short gap instead |
| Price | Per process, per add-on, per GB | Your server. Ployz is free on any number of servers, custom domains included |
What comes with it.
- Your coding agent runs it. Paste one line into Claude Code, Codex or Cursor and it installs Ployz, adds your server and ships the repo. Every deploy, restart or delete your agent asks for waits for you to approve, and no setting turns that off.
- A restore point for Postgres. Restore it, or move the database to a bigger server with seconds of downtime (how, in the docs).
- Monitoring and searchable logs for Uvicorn, your worker and every server, with an email when a service crashes.
- Postgres from your laptop.
ployz service port-forwardopens the database locally forpsqlor a GUI, with no public port.
If you'd rather stay on a hosted platform, Railway alternatives, ranked by price compares the options.
Questions
How do I deploy a FastAPI app with Postgres to my own server?
Run your app with Uvicorn behind an HTTPS proxy, run Postgres next to it on a private network, and run alembic upgrade head once before each deploy. With Ployz, ployz up --server root@your-server installs everything on the server and builds FastAPI with no Dockerfile; you add Postgres in one click, set DATABASE_URL and add the pre-deploy command.
Where is the cheapest place to host FastAPI?
A server you rent: a 4 GB Hetzner CX23 runs a FastAPI app and Postgres for about $7 a month, and Ployz is free on it. The same small app with Postgres costs about $14 on Railway.
Should I use Uvicorn workers or replicas for FastAPI?
Replicas, when your platform runs several containers. FastAPI's docs recommend a single Uvicorn process per container when replication is handled at the cluster level. On Ployz you set the replica count, up to 50 per service across your servers.
How do I run Alembic migrations on deploy?
Set alembic upgrade head as the pre-deploy command. It runs once with the new code before any replica is replaced, and a failed migration stops the deploy while the old version keeps serving.
Do I need a Dockerfile to deploy FastAPI?
No. Railpack detects Python and FastAPI, installs your dependencies with pip, Poetry, PDM, uv or Pipenv, and starts Uvicorn. Set a start command like fastapi run app/main.py --port $PORT if your app isn't main.py at the root.
Can my coding agent deploy my FastAPI app?
Yes. Paste "Read ployz.dev/agents.md and deploy this repo to my server." into Claude Code, Codex or Cursor. It installs the CLI, registers ployz mcp and deploys. Every deploy, restart or delete your agent asks for waits for you to approve, and no setting turns that off.
What does Ployz cost?
Nothing, on any number of servers, with unlimited projects, preview environments, custom domains and members, and the dashboard is hosted for you. You pay your server provider for the servers.
Your servers. The whole platform. Free on your own servers.
Deploy your appFacts checked 2026-11-15.