---
title: "Deploy FastAPI - PostgreSQL"
description: "A comprehensive FastAPI and PostgreSQL template."
category: "Starters"
url: https://railway.com/deploy/IhHgYS
---

# Deploy FastAPI - PostgreSQL

A comprehensive FastAPI and PostgreSQL template.

**[Deploy FastAPI - PostgreSQL on Railway](https://railway.com/template/IhHgYS)**

- **Creator:** Mark Chen's Projects
- **Category:** Starters
- **Total deploys:** 172

## Template content

### Postgres https://devicons.railway.app/i/postgresql.svg

- **Image:** ghcr.io/railwayapp-templates/postgres-ssl:latest

### Fullstack-FastAPI

- **Source:** yuting1214/Fullstack-FastAPI
- **Public domain:** Yes

## Documentation

## Overview

The most complete FastAPI + PostgreSQL template on Railway — fully async, production-ready, and built with modern Python best practices. Skip weeks of boilerplate and start building your API in minutes.

Whether you're prototyping a side project or scaffolding a production service, this template gives you everything you need out of the box: async database access, authenticated API docs, structured project layout, and one-click deployment.

## Why This Template?

* **Fully async from top to bottom**: Every endpoint, CRUD operation, and database call is non-blocking — no thread pool bottlenecks, no mixed sync/async confusion. Just clean, fast async Python.

* **SQLAlchemy 2.0 + PostgreSQL**: Modern ORM with `select()` queries, `async_sessionmaker`, and native UUID support. Auto-creates tables on startup, disposes connections on shutdown — zero manual setup.

* **Authenticated API docs**: `/docs` and `/redoc` are protected behind session-based login using a pure ASGI middleware (no `BaseHTTPMiddleware` overhead). Your API documentation stays private until you're ready to share.

* **Production-grade performance**: FastAPI 0.139 with Rust-powered JSON serialization (pydantic-core), `uvloop` + `httptools` for maximum throughput, and GZIP compression.

* **Tuned for your Railway bill**: ~62MB idle memory (not the typical 150MB Python footprint) — multi-stage image, glibc arena capping, precompiled bytecode, no wrapper processes. Railway bills by memory per minute; this template respects that.

* **Modern Python tooling**: Managed with `uv` and `pyproject.toml` — fast, reproducible installs with no dependency conflicts. Python 3.12, Pydantic v2, and clean `src/` project layout.

* **Ready to extend**: Clean separation between API endpoints, service layer, models, and schemas. Add new resources by following the existing `messages` pattern — no guesswork needed.

## What's Included

* FastAPI with async CRUD endpoints (Create, Read, Update, Delete)
* PostgreSQL with SQLAlchemy 2.0 async engine
* Time-ordered UUIDv7 primary keys (PostgreSQL 18-ready)
* Alembic async migrations
* Pydantic v2 request/response validation
* Session-based authentication for API docs
* `/health` endpoint wired for Railway healthchecks
* Environment-driven configuration (`.env.example` provided)
* Docker multi-stage build
* Async test suite with pytest
* Locust load testing configuration

## Quick Start

1. Click **Deploy** — you'll be prompted for `USER_NAME` and `PASSWORD` (your API docs login) before the FastAPI app + PostgreSQL database provision
2. Left them empty? No problem — credentials are auto-generated and printed once in the deploy logs
3. Visit your deployment URL — your API is live

## Learn More

* [GitHub](https://github.com/yuting1214/Fullstack-FastAPI)
* [Changelog](https://github.com/yuting1214/Fullstack-FastAPI/blob/main/CHANGELOG.md)
* [FastAPI Documentation](https://fastapi.tiangolo.com/)


## Similar templates

- [open-excalidraw](https://railway.com/deploy/open-excalidraw) — Self-hostable collaborative drawing built on Excalidraw
- [caring-vibrancy](https://railway.com/deploy/caring-vibrancy) — Deploy and Host caring-vibrancy with Railway
- [Appsmith](https://railway.com/deploy/appsmith-1) — Low-code platform for internal tools, dashboards, and admin panels.

Open this page in a browser: https://railway.com/deploy/IhHgYS
