Autostop/autostart Machines

Your app can meet peak demand without keeping extra Machines running. Use autostop/autostart to automatically start and stop or suspend existing Machines based on incoming requests. Fly Machines are fast to start and stop, and you don’t pay for their CPU and RAM when they’re in a stopped or suspended state.

Get all the details of how Fly Proxy autostop/autostart works.

When to use autostop/autostart

Autostop/autostart works well for apps with highly variable workloads, for smaller apps with low or sporadic traffic, and for most apps that aren’t receiving requests continuously. You can reduce resource usage and costs by using autostop/autostart to manage your Fly Machines as demand decreases and increases. You’ll never have to run excess Machines to handle peak load; you’ll only run, and get charged for, the number of Machines that you need. You can choose to keep one or more Machines running in your primary region.

Configure autostop/autostart

The autostop/autostart settings are part of each service in an app’s fly.toml file. See the [[services]] or [http_service] docs for details about service configuration. You can also add services to private apps.

Autostop/autostart settings:

  • auto_stop_machines: The action, if any, that Fly Proxy should take when the app is idle for several minutes.
    • The options are "off" (equivalent to false), "stop" (equivalent to true), or "suspend".
    • If "off", Fly Proxy will never stop Machines. If "stop", Fly Proxy stops Machines when the app has excess capacity. If "suspend", Fly Proxy suspends Machines (if possible) when the app has excess capacity. Starting a Machine from a suspended state is faster than starting a Machine from a stopped state, but there are some caveats that you should know about.
  • auto_start_machines: Whether Fly Proxy should automatically start Machines based on requests and capacity.
  • min_machines_running: The minimum number of Machines to keep running in the primary region when auto_stop_machines is set to "stop" or "suspend".

Example configuration:

...
[[services]]
  internal_port = 8080
  protocol = "tcp"
  auto_stop_machines = "stop"
  auto_start_machines = true
  min_machines_running = 1
...

In the preceding example, Fly Proxy will automatically stop Machines when the app has excess capacity and start them again when needed based on traffic to the app. The app will eventually scale down to one running Machine in the primary region if there’s no traffic.

Concurrency limits configured for services in the fly.toml file also affect how autostop/autostart works: Fly Proxy uses the concurrency soft_limit setting for each Machine to determine if there’s excess capacity per region.

Autostop/autostart configuration recommendations

In general, unless your app shuts itself down when idle, we recommend setting auto_stop_machines and auto_start_machines so that they are both enabled or both disabled, to avoid having Machines that either never start or never stop. For example, if auto_start_machines = false and auto_stop_machines = "stop", then Fly Proxy automatically stops your Machines when there’s low traffic but doesn’t start them again. When all or most of your Machines stop, requests to your app could start failing.

Minimum number of Machines running

To keep one or more Machines running all the time in your primary region, set min_machines_running to 1 or higher. If min_machines_running = 1 and there’s no traffic to your app, then Fly Proxy will stop Machines until eventually there is only one Machine running in your primary region. min_machines_running has no effect unless you set auto_stop_machines to "stop" or "suspend".

Maximum number of Machines running

There’s no “maximum machines running” setting, because the maximum number of Machines is the total number of Machines in your app.

Fly Proxy autostop/autostart never creates or destroys Machines for you. The maximum number of running Machines is the number of Machines created for your app on launch, or using fly scale count or fly machine clone. For example, if you want to have a maximum of 10 Machines available to service requests, then you need to create 10 Machines for your app. Learn more about scaling the number of Machines.

Keep all Machines running continuously

If you need all your app’s Machines to run continuously, then you can set auto_stop_machines to "off" and auto_start_machines to false to turn off autostop/autostart completely.

If you only need a certain number of your app’s Machines to run continuously, then you can set auto_stop_machines to "suspend" or "stop" and min_machines_running to 1 or higher. Note that min_machines_running only applies to your app’s primary region.

Private apps

Requests to apps without services configured on your private network don’t get routed through Fly Proxy and so Machines can’t be automatically stopped or started by Fly Proxy. To use Fly Proxy autostart/autostart for private apps, set up services and use a Flycast private IPv6 address. See Flycast - Private Fly Proxy Services and Autostop/autostart private apps.

Apps that shut down when idle

Setting your app to automatically stop or suspend Machines when there’s excess capacity using auto_stop_machines can be a substitute for when your app doesn’t shut itself down automatically after a period of inactivity. If your app already shuts down when idle, then you can set auto_start_machines = true and auto_stop_machines = "off" to have Fly Proxy automatically restart the Machines stopped by your app.

If you want a custom shutdown process for your app, then you can code your app to exit when idle.

Here are some examples:

Fly Postgres also supports scaling to zero.

Default settings

The defaults differ for new apps created with fly launch and for apps with no settings configured for autostop/autostart.

Apps created with fly launch

When you create a new app using the fly launch command, the default settings in fly.toml are:

...
[http_service]
  internal_port = 8080
  force_https = true
  auto_stop_machines = "stop"
  auto_start_machines = true
  min_machines_running = 0
...

Apps with no autostop/autostart settings

For apps that don’t explicitly specify any autostop/autostart settings in fly.toml, Fly Proxy will automatically start stopped Machines when needed, but won’t automatically stop or suspend them.