Deploy to Railway & Fly.io

Domains, Monitoring, Costs and Launch

30 分钟

Custom domains

  • Railway: add a custom domain to the service and create the CNAME record it shows.
  • Fly.io: fly certs add www.example.com, then create the DNS records fly certs show lists. Certificates renew automatically.

Redirect to one canonical host and enforce HTTPS.

Monitoring

  • Platform logs and metrics for CPU, memory, restarts.
  • Sentry for application errors, an uptime monitor on /api/health, and heartbeat checks for scheduled jobs.
  • Alerts on restart loops and memory near the limit.

Cost control

Usage-based billing is efficient but can surprise you:

  • Set usage limits or alerts in the dashboard.
  • Stop or scale down idle staging environments.
  • Use auto-stop for low-traffic apps where a short cold start is acceptable.
  • Watch bandwidth from large downloads; move big files to object storage with a CDN.

Rollbacks

  • Railway: redeploy a previous deployment from the service's deployments list.
  • Fly.io: fly releases lists versions; fly deploy --image <previous image> redeploys an older image.

Remember that rollbacks restore code, not data.

Production checklist

  • [ ] App listens on the platform port; health check configured
  • [ ] Secrets set with the platform tools, separate per environment
  • [ ] Migrations run once per deploy (pre-deploy / release command)
  • [ ] Database in the same region, backups tested
  • [ ] Stateless instances: Redis for sessions and limits, object storage for uploads
  • [ ] Workers and cron jobs separate from web processes
  • [ ] Custom domain, HTTPS, canonical redirect
  • [ ] Monitoring, alerts and usage limits
  • [ ] Rollback procedure documented

Final project

Deploy the same Flask + PostgreSQL + Redis app to both Railway and Fly.io, with a worker, a scheduled job, a custom domain and monitoring on each. Compare setup time, response times from two locations, monthly cost estimates and the rollback experience, and write a recommendation for a client.

Check yourself

  • How do you add a custom domain on each platform?
  • What are three ways to keep usage-based bills under control?
  • Why does a rollback not undo a migration?

你的进度只保存在此浏览器中。

提交审核(10 积分)