GeekHub Learn
Module
Lesson 10.44 of 5 in this module2 min read Module 10: Deploying AI Apps

Railway for FastAPI backends

When your AI app needs a long-running backend (RAG ingest, custom embedding pipelines), Railway is the cheapest way to host it.

Vercel is a courier for parcels. Railway is a warehouse where the worker actually lives.

Railway runs containerized services with a generous free trial and pay-as-you-grow pricing. Connect a GitHub repo, set env vars, deploy. It runs persistently (no cold starts unless you want them).

Use it for:

  • FastAPI backends
  • Persistent vector DB hosts
  • Background workers (Celery, RQ)
  • Scheduled ingest jobs

A minimal FastAPI:

# main.py
from fastapi import FastAPI
from pydantic import BaseModel
from openai import OpenAI
import os

app = FastAPI()
client = OpenAI()

class Q(BaseModel):
    question: str

@app.post("/chat")
def chat(q: Q):
    r = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": q.question}],
    )
    return {"answer": r.choices[0].message.content}

requirements.txt:

fastapi
uvicorn
openai

Procfile (Railway):

web: uvicorn main:app --host 0.0.0.0 --port $PORT

Deploy: connect GitHub repo to Railway, set OPENAI_API_KEY, click deploy.

Visualize it

Architecture: Next.js on Vercel to FastAPI on Railway to OpenAI/Anthropic/Gemini.

Try it now

Deploy the FastAPI above. Hit /chat from your terminal with curl.

Hands-on lab

Build a public /summarize endpoint that takes text and returns a 3-sentence summary. Deploy. Test.

Try it now

When does FastAPI on Railway beat Next.js API routes on Vercel?

Common mistakes

  • Forgetting the $PORT env var
  • Not pinning Python and library versions
  • Leaving spend limits open

Debugging tip

If deploys fail, check the build log for missing system libs. Sometimes you need apt packages declared in a nixpacks.toml.

Challenge

Add a background ingest endpoint (/ingest) that downloads a PDF URL, chunks it, embeds, and stores in a free Postgres + pgvector hosted on Railway.

Where this shows up

  • Production FastAPI backends
  • Scheduled crawlers
  • Worker services for AI pipelines

From the field

In 2026, the dominant indie stack is Next.js on Vercel + FastAPI on Railway + Supabase for DB + ChromaDB or pgvector for retrieval. Master this and you can ship anything.

Recap

Railway is your "real backend" host. Cheap, persistent, container-friendly. Pair it with Vercel for full-stack AI apps.


Quick recall

3 prompts · think before you flip

Prompt 1 of 3

When use Railway over Vercel?

Quiz time

1 question · tap an answer to check it

  1. 1. A long-running Python job is best deployed to

Finished lesson 10.4?

Mark complete to update your module progress and unlock the streak.

Loading