Skip to content

Fly.io Scale-to-Zero Configuration

Scale-to-zero is a Fly.io feature that automatically shuts down VMs after a period of inactivity to save costs in non-production environments. VMs automatically restart when new traffic arrives.

Activity is measured as: Traffic via the Fly proxy (flycast)

Key behaviors:

  • VMs shut down after configured inactivity period
  • VMs auto-restart when requests arrive
  • First request after wake-up will be slower (cold start)
  • Ongoing requests after wake-up should perform normally

Scale-to-zero is configured differently for generic applications vs. Postgres databases.

Add these settings to your fly.toml:

[http_service]
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0

What this means:

  • auto_stop_machines = true - Fly will automatically stop idle machines
  • auto_start_machines = true - Fly will automatically start stopped machines when traffic arrives
  • min_machines_running = 0 - Allow all machines to stop when idle

Add these settings to your Postgres app fly.toml:

[env]
FLY_SCALE_TO_ZERO = '1h'
[[services]]
protocol = 'tcp'
internal_port = 5432
auto_stop_machines = true
auto_start_machines = true

What this means:

  • FLY_SCALE_TO_ZERO = '1h' - Shut down after 1 hour of inactivity
  • Service configuration includes the same auto-start/stop settings as generic apps

Scale-to-zero wake-up doesn’t always work reliably. If you experience issues:

  1. Check machine status: fly status --all -a your-app-name
  2. Manually restart if needed: fly apps restart your-app-name

Postgres instances may shut down faster than the configured FLY_SCALE_TO_ZERO timeout. This appears to be a Fly.io platform issue.

To disable scale-to-zero for a specific machine:

Terminal window
fly machines update $machine_id --env FLY_SCALE_TO_ZERO=""

Good for:

  • Staging environments
  • Demo environments
  • Development environments
  • Any environment with intermittent usage

Not recommended for:

  • Production environments
  • Applications requiring consistent response times
  • High-availability scenarios
Terminal window
# Check app health
fly checks list -a your-app-name
# View all machines and their status
fly status --all -a your-app-name
# List machines
fly machines list -a your-app-name
# Manually start a specific machine
fly machines start machine_id