Skip to content
moai-platform-railway logo

Moai Platform Railway

moai-platform-railway

Railway container deployment specialist covering Docker, multi-service architectures, persistent volumes, and auto-scaling. Use when deploying containerized full-stack applications.

mattnigh/skills_collection0installs24stars

SKILL.md

Full skill instructions

moai-platform-railway: Container Deployment Specialist

Quick Reference (30 seconds)

Railway Platform Core: Container-first deployment platform with Docker and Nixpacks builds, multi-service architectures, persistent volumes, private networking, and auto-scaling capabilities.

Railway Optimal Use Cases

Container Workloads:

  • Full-stack containerized applications with custom runtimes
  • Multi-service architectures with inter-service communication
  • Backend services requiring persistent connections (WebSocket, gRPC)
  • Custom runtime requirements (Python, Go, Rust, Elixir)
  • Database-backed applications with managed PostgreSQL, MySQL, Redis

Infrastructure Requirements:

  • Persistent volume storage for stateful workloads
  • Private networking for secure service mesh
  • Multi-region deployment for global availability
  • Auto-scaling based on CPU, memory, or request metrics

Build Strategy Selection

Docker Build: Custom system dependencies, multi-stage builds, specific base images Nixpacks Build: Standard runtimes (Node.js, Python, Go), zero-config, faster builds

Key CLI Commands

railway login && railway init && railway link
railway up                    # Deploy current directory
railway up --detach          # Deploy without logs
railway up --service api     # Deploy specific service
railway variables --set KEY=value
railway logs --service api

Implementation Guide

Phase 1: Docker Deployment Patterns

Multi-Stage Node.js Dockerfile:

FROM node:20-alpine AS deps
WORKDIR /​app
COPY package*.json ./
RUN npm ci --only=production

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
ENV NODE_ENV=production
RUN addgroup --system --gid 1001 nodejs && adduser --system --uid 1001 appuser
COPY --from=deps /​app/​node_modules ./​node_modules
COPY --from=builder /​app/​dist ./​dist
USER appuser
EXPOSE 3000
CMD ["node", "dist/​main.js"]

Python Production Dockerfile:

FROM python:3.12-slim AS builder
WORKDIR /​app
RUN pip install --no-cache-dir poetry
COPY pyproject.toml poetry.lock ./
RUN poetry config virtualenvs.create false && poetry install --no-dev

FROM python:3.12-slim AS runner
WORKDIR /​app
ENV PYTHONUNBUFFERED=1
COPY --from=builder /​usr/​local/​lib/​python3.12/​site-packages /​usr/​local/​lib/​python3.12/​site-packages
COPY . .
RUN useradd --create-home appuser
USER appuser
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

Go Production Dockerfile:

FROM golang:1.23-alpine AS builder
WORKDIR /​app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o main .

FROM alpine:latest AS runner
RUN apk --no-cache add ca-certificates && adduser -D appuser
WORKDIR /​app
COPY --from=builder /​app/​main .
USER appuser
EXPOSE 8080
CMD ["./​main"]

Phase 2: Nixpacks Configuration

Note: Nixpacks is deprecated and in maintenance mode. New services default to Railpack. Existing services continue to work with Nixpacks. To migrate, set builder = "RAILPACK" in railway.toml.

Node.js nixpacks.toml:

[phases.setup]
nixPkgs = ["nodejs-20_x", "pnpm"]

[phases.install]
cmds = ["pnpm install --frozen-lockfile"]

[phases.build]
cmds = ["pnpm build"]

[start]
cmd = "pnpm start"

Python nixpacks.toml:

[phases.setup]
nixPkgs = ["python312", "poetry"]
aptPkgs = ["libpq-dev"]

[phases.install]
cmds = ["poetry install --no-dev"]

[start]
cmd = "poetry run gunicorn app:application --bind 0.0.0.0:$PORT"

Phase 3: Railway Configuration

railway.toml with Nixpacks:

[build]
builder = "NIXPACKS"
buildCommand = "npm run build"
watchPatterns = ["src/​**", "package.json"]

[deploy]
startCommand = "npm start"
healthcheckPath = "/​health"
healthcheckTimeout = 100
restartPolicyType = "ON_FAILURE"
restartPolicyMaxRetries = 5
numReplicas = 2

[deploy.resources]
memory = "512Mi"
cpu = "0.5"

railway.toml with Docker:

[build]
builder = "DOCKERFILE"
dockerfilePath = "./​Dockerfile"

[deploy]
healthcheckPath = "/​api/​health"
healthcheckTimeout = 60
restartPolicyType = "ALWAYS"
numReplicas = 3

[deploy.resources]
memory = "1Gi"
cpu = "1"

Phase 4: Multi-Service Architecture

Multi-Service Monorepo (railway.toml per service):

Each service in a monorepo requires its own railway.toml in its directory.

API Service (apps/​api/​railway.toml):

[build]
builder = "DOCKERFILE"
dockerfilePath = "./​Dockerfile"

[deploy]
startCommand = "node dist/​main.js"
healthcheckPath = "/​health"
numReplicas = 3

Worker Service (apps/​worker/​railway.toml):

[build]
builder = "DOCKERFILE"
dockerfilePath = "./​Dockerfile"

[deploy]
startCommand = "node dist/​worker.js"
numReplicas = 2

Scheduler Service (apps/​scheduler/​railway.toml):

[build]
builder = "DOCKERFILE"
dockerfilePath = "./​Dockerfile"

[deploy]
startCommand = "node dist/​scheduler.js"
cronSchedule = "*/​5 * * * *"

Service Variable References: Use Railway's variable reference syntax in service settings for cross-service communication with format ${{ServiceName.VARIABLE_NAME}}.

Private Networking:

const getInternalUrl = (service: string, port = 3000): string => {
  const domain = process.env[`${service.toUpperCase()}_RAILWAY_PRIVATE_DOMAIN`]
  return domain ? `http://${domain}:${port}` : `http://localhost:${port}`
}

app.get('/​health', (req, res) => {
  res.json({
    status: 'healthy',
    service: process.env.RAILWAY_SERVICE_NAME,
    replica: process.env.RAILWAY_REPLICA_ID
  })
})

Phase 5: Persistent Volumes

Volume Configuration:

[deploy]
startCommand = "npm start"

[[volumes]]
mountPath = "/​app/​data"
name = "app-data"
size = "10Gi"

[[volumes]]
mountPath = "/​app/​uploads"
name = "user-uploads"
size = "50Gi"

Persistent Storage Pattern:

import { join } from 'path'
import { existsSync, mkdirSync, writeFileSync, readFileSync } from 'fs'

const VOLUME_PATH = process.env.RAILWAY_VOLUME_MOUNT_PATH || '/​app/​data'

class PersistentStorage {
  constructor() {
    if (!existsSync(VOLUME_PATH)) mkdirSync(VOLUME_PATH, { recursive: true })
  }
  write(file: string, data: Buffer | string) { writeFileSync(join(VOLUME_PATH, file), data) }
  read(file: string): Buffer { return readFileSync(join(VOLUME_PATH, file)) }
}

Phase 6: Auto-Scaling

Resource-Based Scaling:

[deploy.scaling]
minReplicas = 2
maxReplicas = 10
targetCPUUtilization = 70
targetMemoryUtilization = 80

Request-Based Scaling:

[deploy.scaling]
minReplicas = 1
maxReplicas = 20
targetRequestsPerSecond = 100
scaleDownDelaySeconds = 300

Application Metrics:

import { register, Counter, Histogram } from 'prom-client'

const httpRequests = new Counter({
  name: 'http_requests_total',
  help: 'Total HTTP requests',
  labelNames: ['method', 'status']
})

app.get('/​metrics', async (req, res) => {
  res.set('Content-Type', register.contentType)
  res.end(await register.metrics())
})

Multi-Region Deployment

Available Regions: us-west1 (Oregon), us-east4 (Virginia), europe-west4 (Netherlands), asia-southeast1 (Singapore)

railway up --region us-west1
railway up --region europe-west4

Region Configuration:

[[deploy.regions]]
name = "us-west1"
replicas = 3

[[deploy.regions]]
name = "europe-west4"
replicas = 2

Database Read Replica:

const primaryPool = new Pool({ connectionString: process.env.DATABASE_URL })
const replicaPool = new Pool({ connectionString: process.env.DATABASE_REPLICA_URL })

async function query(sql: string, params?: any[]) {
  const isRead = sql.trim().toLowerCase().startsWith('select')
  return (isRead ? replicaPool : primaryPool).query(sql, params)
}

CI/​CD Integration

GitHub Actions:

name: Railway Deploy
on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/​checkout@v4
      - run: npm i -g @railway/​cli
      - run: railway up --detach
        env:
          RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}

Rollback Commands:

railway deployments list
railway rollback <deployment-id>
railway rollback --previous

Works Well With

  • moai-platform-vercel - Edge deployment for frontend applications
  • moai-domain-backend - Backend service architecture patterns
  • moai-lang-python - Python FastAPI deployment configurations
  • moai-lang-typescript - TypeScript Node.js deployment patterns

Status: Production Ready | Version: 1.1.0 | Updated: 2025-12-30

More skills from mattnigh

spring-framework-patterns logo
mattnigh/skills_collection

spring-framework-patterns

Comprehensive Spring Framework and Spring Boot best practices including dependency injection patterns, bean lifecycle and scopes, REST API development, Spring Data JPA, service layer design, Spring Security, testing strategies, caching, AOP, async processing, error handling, and common anti-patte...

24 0
View

TypeScript厳格モードによる型安全性設計を専門とするスキル。 📖 参照書籍: - 『Effective TypeScript』(Dan Vanderkam): 型設計 📚 リソース参照: - `resources/Level1_basics.md`: レベル1の基礎ガイド - `resources/Level2_intermediate.md`: レベル2の実務ガイド - `resources/Level3_advanced.md`: レベル3の応用ガイド - `resources/Level4_expert.md`: レベル4の専門ガイド - `resources/di...

24 0
View
deploying-cloud-k8s logo
mattnigh/skills_collection

deploying-cloud-k8s

Deploys applications to cloud Kubernetes (AKS/GKE/DOKS) with CI/CD pipelines. Use when deploying to production, setting up GitHub Actions, troubleshooting deployments. Covers build-time vs runtime vars, architecture matching, and battle-tested debugging.

24 0
View
moai-alfred-agent-guide logo
mattnigh/skills_collection

moai-alfred-agent-guide

19-agent team structure, decision trees for agent selection, Haiku vs Sonnet model selection, and agent collaboration principles. Use when deciding which sub-agent to invoke, understanding team responsibilities, or learning multi-agent orchestration.

24 0
View
mermaid-diagram-generator logo
mattnigh/skills_collection

mermaid-diagram-generator

Converts architecture descriptions, module specs, or workflow docs into Mermaid diagrams. Use when visualizing brick module relationships, workflows (DDD, investigation), or system architecture. Supports: flowcharts, sequence diagrams, class diagrams, state machines, entity relationship diagrams,...

24 0
View
pre-flight-check logo
mattnigh/skills_collection

pre-flight-check

INVOKE FIRST before any code work. Validates git workflow (branch, issue, worklog) and checks approach. Use at START of every task and END before completing. Prevents skipped steps.

24 0
View
browser-dev-tools logo
mattnigh/skills_collection

browser-dev-tools

This skill should be used when working with browser-rendered artifacts (i.e. Bun, React/React Native) to proactively validate that development work on localhost is being built appropriately and to support debugging browser-rendered content. Use this skill after making frontend changes to verify t...

24 0
View
lead-dev logo
mattnigh/skills_collection

lead-dev

Lead Développeur - Coordination technique opérationnelle, code review, mentoring et livraison. Pair de web-dev-process au niveau OPÉRATIONS.

24 0
View
worker-monitor logo
mattnigh/skills_collection

worker-monitor

Monitor Docker workers, RQ queue health, and auto-scale workers (max 4). Use when: checking job progress, monitoring queue depth, scaling workers up/down, diagnosing slow processing, or waiting for jobs to complete. Referenced by data-quality skill during reprocessing.

24 0
View
quality-advisor logo
mattnigh/skills_collection

quality-advisor

Proactive quality guidance system that monitors artifact creation and provides real-time feedback on documentation quality

24 0
View
bump-version logo
mattnigh/skills_collection

bump-version

This skill should be used when the user wants to bump the version number in the workspace. It updates versions across all pyproject.toml files (root, tde, and tda packages) and the CHANGELOG.md to keep them synchronized.

24 0
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View