fly.toml, giving each process group a name and a command to run at boot. Every defined process runs in its own Fly Machine(s) within the app, which means they donāt compete for resources, and they can be scaled by process group.
The default process group
If you donāt explicitly define any processes, then the Machines in a Fly App belong to the defaultapp process group, and on boot they run whatever entrypoint process the appās Docker image has. (Apps are shipped to Fly.io in Docker images, even though we run VMs, not containers.)
When the fly launch command creates a fly.toml file for your app, the default service defined in the http_service section belongs to the app process group.
Run multiple processes
To run multiple processes, first make sure all the things you want to run are installed in your appās Docker image. Define aprocesses section in your appās fly.toml, pairing process group names with the commands they should run. Hereās an example:
[processes] section in your config, flyctl assumes this is a complete list of your processes. If you want an app process group alongside others, add it to the config explicitly.
Process group commands in a Fly App correspond to CMD in Docker; they donāt replace the ENTRYPOINT of your app image, but will supersede CMD.
Processes and services
Chances are, you only want user requests to hit one of your processes. In the above example, that process isweb. Each serviceās processes key lists the process groups whose Machines receive its requests.
fly launch generates an [http_service] section with processes = ['app']. Once you add a [processes] section without an app group, change that value to the group that serves HTTP:
[[services]] section instead of [http_service], the processes key works the same way. This is an equivalent service for web; use one or the other, not both:
fly.toml has a [processes] section, every [http_service] and [[services]] section must set processes, and every name it lists must be defined in [processes]. Otherwise fly deploy fails config validation with an error like Service has no processes set but app has 2 processes defined.
You can define distinct services for each process that needs to accept connections from Fly Proxy (whether publicly or via Flycast), by creating multiple [[services]] sections in fly.toml.
Important: Make sure processes handle connections on different external ports. Fly Proxy doesnāt know about process groups; it load-balances requests among all Machines with a service configured on the requested port.
Set Machine size per process group
Process groups often need different CPU and memory. Set them infly.toml with one [[vm]] section per group, using the same processes key:
[[vm]] section without a processes key applies to every group that doesnāt have its own [[vm]] section. The [[vm]] section that fly launch generates has no processes key, so it covers all groups until you add group-specific ones. Note the double brackets: [[vm]] is a list, so you can repeat it.
[[mounts]] sections accept a processes key too, but behave differently when itās missing: a [[mounts]] section without processes attaches the volume only to Machines in the default process group (app if itās defined, otherwise the first group name in alphabetical order), not to every group. Set processes explicitly on mounts in apps with more than one group.
Deployment
fly deploy creates at least one Machine for each process group, and destroys all the Machines that belong to any process group that isnāt defined, in your appās fly.toml file. It also updates the command, services, and health checks for each fly deploy-managed Machine on the app; and creates a new app release.
So on the first deployment (either at the end of fly launch or at the first explicit fly deploy), flyctl creates and starts at least one Machine for each process group in fly.toml.
If you add new process groups in an appās [processes] block, then the next fly deploy spins up at least one new Machine to run each new process.
If you remove any process groups from an appās [processes] block, then the next fly deploy destroys the Machines that belong to the deleted process.
For more information about how many Machines are created by fly launch and fly deploy, refer to App Availability and Resiliency.
Scale a process group horizontally
There are two ways to scale the number of Machines in an app. This section provides a summary of horizontal scaling. For more information, refer to Scale the Number of Machines.Scale a process group horizontally with fly scale count
You can scale the number of Machines (up or down) per process group with the fly scale count command. The following example scales the web process group to 8 Machines, and the cron process group to 2 Machines:
--region option. Specify multiple regions and the Machines will be distributed as evenly as possible between them. The following command would create 2 Machines in gru and 2 Machines in bog:
Scale a process group horizontally with fly machine clone
You can also use the fly machine clone and fly machine destroy commands to scale the number of Machines individually within a process group. When you clone a Machine that belongs to a process group, the new Machine is created with the command, services, and checks that are configured on the app for that process.
You can add a region to your app by cloning a Machine into a new region.
First, run fly status to get a list of Machines with IDs and process groups.
The following example clones a Machine into the gru (SĆ£o Paulo) region:
Scale a process group vertically
You can scale Machine CPU and memory settings for an entire process group using thefly scale vm and fly scale memory commands. This section provides a summary of vertical scaling. For more information, refer to Scale Machine CPU and RAM.
Note: The
--process-group option is aliased to -g for faster command entry.web process group to a different preset combination:
fly platform vm-sizes for a list of the valid CPU/RAM preset combinations.
This example changes only the RAM of Machines in the web process group:
If any
[[vm]] section in fly.toml applies to a process group, the next fly deploy resets that groupās Machines to the size in the file. That includes a [[vm]] section without a processes key, like the one fly launch generates, which applies to every group. To keep a size you set with fly scale, update the matching [[vm]] section too. See Set Machine size per process group.