Scale to zero for Node.js applications

Hi everyone,

Some time ago I noticed that there is a nice article about a Minecraft server that has the possibility to scale to zero.

Now we have quite a powerful node.js application that now also runs on fly.io. However, since we are still in the test phase, it is called 1 to 5 times per hour per day.

However, when it is running, we need 1 to 2 gigs of ram to run it properly. However, it is a waste of energy to keep it running continuously.

Is it possible to scale to zero for a Node.js application on Fly.io? The application uses express as web server?

2 Likes

There are two requirements for scaling to zero:

  • Your app must be on the machines platform.
  • Your app must exit with rc of 0 when idle.

You chose the machines platform via specifying --machines on the fly apps create command. You once created you can use your same Dockerfile, fly.toml, etc. Machines is still under active development, but should be fine for tests.

1 Like

Any clarity on what a restart_policy is and what they mean for Machines exiting with various exit-codes, if set?


We run a Node app on machines: Here’s some relevant code bits.

You mean doing this?

let exitCode = 1;
process.exit(exitCode)

process.exit(0) is what we do.