Is it feasible to dynamically deploy multiple machines from a single image, each with its own unique subdomain, using the Fly.io API? Our use case involves creating separate, accessible instances on-demand, potentially running concurrently, and then terminating them when no longer needed. Any guidance on best practices or limitations would be appreciated !!
(each machine host itβs own backend with unique url to access the backend)
Yes, this is one of the use cases we intended with fly-replay
. You run one app that decides where to route traffic, and then individual apps (or machines, see caveats) for backends.
The request sequence would look like this:
- Request comes in to router app
- Router app checks subdomain against cached list of backends
- Router app responds with
fly-replay: <desired-backend>
The basic setup looks like this:
ββββββββββββββββββββββββββββββββββ
β router β
β fly-replay β
βββ¬βββββββββββββββ¬ββββββββββββββ¬ββ
β β β
β β β
β β β
β β β
β β β
β β β
ββββββββββββΌββββ ββββββββΌββββββββ βββΌβββββββββββββ
β β β β β β
β abc.domain β β xyz.domain β β pdq.domain β
β β β β β β
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ
Now, you can do this with multiple machines (fly-replay: instance=<id>
), but in most cases itβs better to create multiple apps, one per backend. This lets you isolate each one to its own private network.
Hereβs a small example:
Thanks for the quick reply! Iβd love to get your opinion before deciding which path to take. Let me provide more context about our use case:
Weβve built a Zoom meeting bot with the following requirements:
- Each instance needs ~4GB RAM and 2 cores to run smoothly
- We need to boot a machine only for the duration of a meeting
- Our initial design involves spawning one machine per meeting for better isolation
- All machines run the same Docker image but with different ENV variables
- Each machine requires a mount
Our main challenge now is deploying these machines and scaling up/down before and after meetings.
Given these requirements, Iβm wondering:
- Does this use case fit better with fly-replay, or should we create apps dynamically?
- Can Fly.io handle rapid scaling of machines with these specs (4GB RAM, 2 cores, mount)?
- Are there any limitations or best practices we should be aware of for this kind of dynamic deployment?
Any insights you can provide would be greatly appreciated as we finalize our production architecture. Thanks!
That bot architecture should work really well with the fly replay setup. We use fly-replay
to establish long lived websocket connections and itβs really nice.
You can actually hold a request in the router, create an app / machine, and then respond with fly-replay
to it, if youβd like.
You can create and remove machines very quickly. Same with volumes. One thing to consider is how many moving parts are involved in our infrastructure:
- Create machine touches a lot more places than
start
does - Similar deal with volumes
- Updating a machine is almost like create, but itβs a bit simpler
The most resilient setup would be to precreate machines / mounts you think youβll need, then leave them stopped until you want to use them.
The quickest thing to build would be something that provisions machines / volumes right when you need them, then issues fly-replay
. Iβd probably start with this and do some testing to see if you need to do more resilience work.
One thing to keep in mind is that there are limits on how many machines you can create. We can raise those, so if you think youβre going to go over 100 at any given time itβs best to send in a request for an increase.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.