Railway
Railway is a deployment platform that makes it easy to deploy containerized applications with built-in databases and automatic scaling.
Why Railway?
- Simple setup: Deploy from GitHub or Docker images
- Built-in services: PostgreSQL, Redis included
- Automatic SSL: Free HTTPS for all deployments
- Fair pricing: Pay for actual usage
Architecture
Railway deploys each service as a separate container:
┌─────────────────────────────────────────┐
│ Railway Project │
│ ┌─────────────┐ ┌─────────────────┐ │
│ │ API Service │ │ Worker Service │ │
│ └──────┬──────┘ └────────┬────────┘ │
│ │ │ │
│ ┌──────┴───────────────────┴──────┐ │
│ │ Internal Network │ │
│ └──────┬───────────────────┬──────┘ │
│ │ │ │
│ ┌──────┴──────┐ ┌──────┴──────┐ │
│ │ PostgreSQL │ │ Redis │ │
│ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────┘
Quick Start
1. Create a Railway Project
- Go to railway.app and sign in
- Click New Project
- Choose Empty Project
2. Add PostgreSQL
- Click + New > Database > Add PostgreSQL
- Railway automatically provisions the database
- Note the
DATABASE_URLfrom the Variables tab
3. Add Redis
- Click + New > Database > Add Redis
- Note the
REDIS_URLfrom the Variables tab
4. Deploy API Service
- Click + New > Docker Image
- Enter:
ghcr.io/weirdfingers/boards-backend:latest - Configure the service:
Settings tab:
- Start Command:
uvicorn boards.api.app:app --host 0.0.0.0 --port $PORT - Port: Leave as auto-detected
Variables tab:
BOARDS_DATABASE_URL=${{Postgres.DATABASE_URL}}
BOARDS_REDIS_URL=${{Redis.REDIS_URL}}
BOARDS_GENERATOR_API_KEYS={"fal": "your-key", "openai": "your-key"}
BOARDS_AUTH_PROVIDER=none
BOARDS_LOG_FORMAT=json
- Click Deploy
5. Deploy Worker Service
- Click + New > Docker Image
- Enter:
ghcr.io/weirdfingers/boards-backend:latest - Configure:
Settings tab:
- Start Command:
boards-worker --log-level info --processes 1 --threads 1
Variables tab:
BOARDS_DATABASE_URL=${{Postgres.DATABASE_URL}}
BOARDS_REDIS_URL=${{Redis.REDIS_URL}}
BOARDS_GENERATOR_API_KEYS={"fal": "your-key", "openai": "your-key"}
BOARDS_INTERNAL_API_URL=http://${{api.RAILWAY_PRIVATE_DOMAIN}}:8800
BOARDS_LOG_FORMAT=json
- Click Deploy
Configuration Files
For generators and storage config, you have two options:
Option 1: Environment Variables
Set config directly in environment:
BOARDS_STORAGE_PROVIDER=s3
AWS_ACCESS_KEY_ID=xxxxx
AWS_SECRET_ACCESS_KEY=xxxxx
Option 2: GitHub Repository
Deploy from a repository with config files:
- Create a repository with:
├── config/
│ ├── generators.yaml
│ └── storage_config.yaml
└── railway.toml
- Create
railway.toml:
[build]
dockerfilePath = "Dockerfile"
[deploy]
startCommand = "uvicorn boards.api.app:app --host 0.0.0.0 --port $PORT"
- Connect repository to Railway
Domain Configuration
Railway Domain
Railway provides a free subdomain:
- Go to your API service
- Click Settings > Networking
- Click Generate Domain
Custom Domain
- Go to Settings > Networking
- Click + Custom Domain
- Enter your domain (e.g.,
api.boards.example.com) - Add the CNAME record to your DNS
Deploy Frontend
- Click + New > GitHub Repo
- Select your frontend repository
- Configure environment variables:
NEXT_PUBLIC_API_URL=https://your-api.railway.app
NEXT_PUBLIC_GRAPHQL_URL=https://your-api.railway.app/graphql
Or use Docker image:
- + New > Docker Image
- Build and push your frontend image to a registry
- Enter the image URL
Scaling
Horizontal Scaling
Railway Pro supports multiple replicas:
- Go to service Settings
- Under Replicas, increase the count
Resource Limits
Configure memory and CPU:
- Go to service Settings
- Adjust Memory and CPU limits
Private Networking
Services communicate via internal network:
# Reference other services
BOARDS_INTERNAL_API_URL=http://${{api.RAILWAY_PRIVATE_DOMAIN}}:8800
The RAILWAY_PRIVATE_DOMAIN variable is automatically set.
Monitoring
Logs
View logs in the Railway dashboard:
- Click on a service
- Go to Deployments tab
- Click View Logs
Or use the CLI:
railway logs
Metrics
Railway shows basic metrics:
- CPU usage
- Memory usage
- Network traffic
For advanced monitoring, integrate with external tools.
CI/CD
Automatic Deploys
Railway automatically deploys when:
- You push to the connected branch
- Docker image tag is updated (requires redeploy)
Manual Deploys
# Install Railway CLI
npm install -g @railway/cli
# Login
railway login
# Deploy
railway up
Deploy Hook
Use webhooks to trigger deploys:
- Go to project Settings
- Find Deploy Hooks
- Use the webhook URL in your CI pipeline
Environment Templates
Create reusable templates with Railway's template feature:
- Configure your project
- Click Settings > Create Template
- Share the template URL for one-click deploys
Cost Estimation
Railway pricing (as of writing):
| Resource | Cost |
|---|---|
| Compute | $0.000231/vCPU/min |
| Memory | $0.000231/GB/min |
| PostgreSQL | Included in compute |
| Redis | Included in compute |
Estimated monthly costs:
- Small deployment: $5-15
- Medium deployment: $20-50
- Large deployment: $100+
Free tier includes $5/month credit.
Troubleshooting
Service Won't Start
- Check Deployments for build/deploy logs
- Verify environment variables are set
- Check start command syntax
Database Connection Failed
- Verify
${{Postgres.DATABASE_URL}}syntax - Check PostgreSQL service is healthy
- Test connection in Railway shell:
railway run python -c "from boards.db import engine; print(engine.connect())"
Redis Connection Failed
- Verify
${{Redis.REDIS_URL}}syntax - Check Redis service is healthy
- Ensure REDIS_URL uses correct format
Next Steps
- Storage Configuration - Set up S3 or other storage
- Authentication - Configure auth providers
- Monitoring - Add external monitoring