Scale to zero question

Sorry I’m a bit lazy to just go ahead and try it with a simple app so I’ll just ask in the public forum :smiley:

I’ve seen a couple of blog posts recently mentioning doing scale-to-zero using Fly machines. From just skimming through their code/blog posts there wasn’t anything in particular that I’ve seen (or might have missed it) which calls fly apis to stop/start machines. So my question is, once you use a Fly machine to deploy an app and if the app just triggers a machine stop somehow, would fly proxy or something similar just trigger the VM startup when a request to the public ip is received ?

You don’t have to explicitly use Fly APIs to stop machines (though, you could); just exiting the process that’s keeping the VM up is all you need to impl (ref).

Finally, the trick we have up our sleeve: it spawns a code-server, with the /project folder open, listening on port 9090—but we don’t expose this port directly. Tired Proxy maps port 8080 to 9090, and if there’s no incoming HTTP connection for $TIME_TO_SHUTDOWN seconds, it exits. That’s it. That’s the whole trick.

From: Fly blog.

Yep. But don’t forget to assign a public-ip to your machine app, though.

Machines are also the spawning ground for new platform features like wake-on-request (also known as scale-to-zero). You can stop a running machine to save on compute costs. It then may be started automatically when a request arrives at the Fly proxy.

From: Fly docs.

Note, flyctl makes is easier to experiment with Fly Machine apps if you are already familiar with regular Fly apps.

Great, thanks @ignoramous