| name | deploying-to-railway |
| description | Deploy Python services to Railway with PostgreSQL/pgvector. Use when deploying web services, workers, or databases. Covers CLI workflow, variable linking, and multi-service patterns. |
Deploying to Railway
Guide for deploying Python services to Railway.
Prerequisites
npm install -g @railway/cli
railway login
Basic Workflow
1. Link Project
cd /path/to/service
railway link
2. Add PostgreSQL (if needed)
railway add
IMPORTANT: Standard Postgres does NOT have pgvector. For vector search:
3. Set Environment Variables
railway variables set KEY="value"
railway variables set 'DATABASE_URL=${{Postgres.DATABASE_URL}}'
railway variables set 'DATABASE_URL=${{pgvector.DATABASE_URL}}'
4. Deploy
railway up --detach
5. Get Domain
railway domain
Multi-Service Pattern (API + Worker)
Deploy API Service
railway link
railway up --detach
Add Worker Service
railway add --service worker
railway service link worker
railway variables set 'DATABASE_URL=${{pgvector.DATABASE_URL}}'
railway variables set OPENAI_API_KEY="$OPENAI_API_KEY"
railway up --detach
Gotchas
- pgvector not available - Use pgvector template, not standard Postgres
- Interactive prompts - Some commands need interactive mode (run manually)
- Variable references - Use
${{ServiceName.VARIABLE}} syntax
- Dockerfile required - For custom Python services, include Dockerfile
- Procfile - Railway can use Procfile for multi-process apps
Useful Commands
railway status
railway variables
railway logs
railway service status
railway redeploy --yes
Example Dockerfile
FROM python:3.11-slim
WORKDIR /app
RUN apt-get update && apt-get install -y libpq-dev gcc && rm -rf /var/lib/apt/lists/*
COPY pyproject.toml ./
COPY myapp/ ./myapp/
RUN pip install --no-cache-dir .
CMD ["gunicorn", "--bind", "0.0.0.0:8080", "--workers", "2", "myapp.app:app"]