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.
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. A long-running Python job is best deployed to
Finished lesson 10.4?
Mark complete to update your module progress and unlock the streak.