Railway

Deploy FastAPI - PostgreSQL

A comprehensive FastAPI and PostgreSQL template.

Deploy FastAPI - PostgreSQL

/var/lib/postgresql/data

Just deployed

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


Template Content

More templates in this category

View Template
NEW
open-excalidraw
Self-hostable collaborative drawing built on Excalidraw

Prateek Mohanty
1
View Template
caring-vibrancy
Deploy and Host caring-vibrancy with Railway

5
View Template
Flask WebSocket Chat
Single file, realtime multi-user websocket chat using flask-socketio

Clement Ochieng
3