railway-deployment
Railway.app deployment patterns, environment management, and production best practices. Applied automatically when working with Railway deployments.
What this skill does
# Railway Deployment Knowledge Base
## Railway Platform Overview
Railway is a modern PaaS that deploys applications from Git repositories with automatic builds and deployments.
### Key Concepts
- **Project**: Container for all services and environments
- **Service**: Individual deployable unit (backend, frontend, database)
- **Environment**: Isolated deployment target (staging, production)
- **Deployment**: Specific version of code running in an environment
## Auto-Deploy Configuration
Railway automatically deploys when you push to configured branches:
| Branch | Environment | Trigger |
|--------|-------------|---------|
| `develop` | Staging | Push to develop |
| `main` | Production | Push to main |
### Setting Up Auto-Deploy
1. Go to Railway Dashboard → Project → Settings
2. Under "Deployments", configure:
- Source branch for each environment
- Build command (auto-detected usually)
- Start command
## Project Structure Patterns
### Monorepo (Multiple Services)
```
project/
├── frontend/
│ ├── Dockerfile
│ └── package.json
├── backend/
│ ├── Dockerfile
│ └── requirements.txt
└── railway.json
```
### Single Service
```
project/
├── Dockerfile (or detected runtime)
├── package.json / requirements.txt
└── railway.json (optional)
```
## railway.json Configuration
```json
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "DOCKERFILE",
"dockerfilePath": "Dockerfile"
},
"deploy": {
"numReplicas": 1,
"healthcheckPath": "/health",
"healthcheckTimeout": 300,
"restartPolicyType": "ON_FAILURE"
}
}
```
## Dockerfile Best Practices for Railway
```dockerfile
# Multi-stage build for smaller images
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM node:20-alpine AS runner
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
EXPOSE 3000
CMD ["node", "dist/index.js"]
```
### Python Example
```dockerfile
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
```
## Environment Variables
### Railway-Provided Variables
```
RAILWAY_ENVIRONMENT=production
RAILWAY_SERVICE_NAME=backend
RAILWAY_PROJECT_ID=xxx
PORT=<assigned port>
```
### Common Application Variables
```
ENVIRONMENT=production
DATABASE_URL=postgresql://...
REDIS_URL=redis://...
API_KEY=xxx
CORS_ORIGINS=https://myapp.com
```
## Health Checks
Railway performs health checks to ensure your app is running:
```python
# FastAPI example
@app.get("/health")
async def health_check():
return {"status": "healthy"}
```
```javascript
// Express example
app.get('/health', (req, res) => {
res.json({ status: 'healthy' });
});
```
## Networking
### Internal Networking
Services within the same project can communicate via internal DNS:
```
http://backend.railway.internal:8000
```
### External Access
- Railway provides `*.up.railway.app` domains
- Custom domains can be configured in settings
## Logging
### Viewing Logs
```bash
# Via CLI
railway logs
railway logs --environment production
railway logs -n 100 # Last 100 lines
# Via Dashboard
Project → Service → Logs tab
```
### Structured Logging Best Practices
```python
import logging
import json
logging.basicConfig(
format='%(message)s',
level=logging.INFO
)
def log_json(level, message, **kwargs):
log_entry = {"message": message, **kwargs}
getattr(logging, level)(json.dumps(log_entry))
```
## Scaling
### Horizontal Scaling
```json
// railway.json
{
"deploy": {
"numReplicas": 3
}
}
```
### Resource Limits
Configure in Railway Dashboard:
- Memory limit
- CPU limit
- Instance count
## Database Connections
### Connection Pooling
For production, use connection pooling:
```python
# SQLAlchemy with pool
engine = create_engine(
DATABASE_URL,
pool_size=5,
max_overflow=10,
pool_pre_ping=True
)
```
## Deployment Monitoring
### Key Metrics to Watch
- Build time
- Deployment status
- Memory usage
- CPU usage
- Response times
- Error rates
### Alerts
Configure alerts in Railway Dashboard for:
- Deployment failures
- High memory usage
- Service crashes
## Rollback Procedures
### Quick Rollback
1. Go to Railway Dashboard
2. Select service → Deployments
3. Click "Rollback" on previous healthy deployment
### Git-Based Rollback
```bash
git revert HEAD
git push origin main
# Railway auto-deploys reverted code
```
## Cost Optimization
- Use multi-stage Docker builds (smaller images)
- Set appropriate resource limits
- Use sleep/hibernation for staging if not needed 24/7
- Monitor usage in Railway Dashboard
## Troubleshooting
| Symptom | Check |
|---------|-------|
| Build fails | Dockerfile syntax, dependencies |
| Deploy hangs | Health check endpoint, startup time |
| 502 errors | App not binding to PORT env var |
| Slow performance | Resource limits, database queries |
| Missing env vars | Railway Dashboard → Variables |
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.