Skip to content

Fly

Host your Durable Objects on Fly.io, and the control plane runs on Fly Machines with a volume each, behind the App’s fly.dev address. Each pool is a private Fly Service, and any Fly Service calls the rooms by name.

src/cluster.ts
import * as RivetFly from "@alchemy.run/rivet/Fly";
import * as Layer from "effect/Layer";
export const Cluster = RivetFly.MachineControlPlane("Rivet");
export const Default = RivetFly.MachinePool("Default").pipe(Layer.provide(Cluster));

Install @alchemy.run/fly and finish Fly setup.

You get three engine Machines, each with a volume, sharing a Tigris bucket. The App’s fly.dev address is the endpoint.

src/cluster.ts
export const Cluster = RivetFly.MachineControlPlane("Rivet", {
region: "fra",
guest: { cpus: 4, memoryMb: 8192 },
diskSize: 50,
});
src/cluster.ts
export const Default = RivetFly.MachinePool("Default", { replicas: 2, region: "fra" }).pipe(
Layer.provide(Cluster),
);

The pool has no public address.

ServicesPool runs Rivet Services on Fly Machines that take no traffic from Fly’s proxy:

src/cluster.ts
export const Services = RivetFly.ServicesPool("Services").pipe(Layer.provide(Cluster));
src/api.ts
export default class Api extends Fly.Service<Api>()(
"Api",
{ main: import.meta.url },
Effect.gen(function* () {
const rooms = yield* Room;
return {
fetch: Effect.gen(function* () {
const visitors = yield* rooms.getByName("lobby").join();
return yield* HttpServerResponse.json({ visitors });
}),
};
}),
) {}

Every option, with its default, is in the reference: MachineControlPlane, MachinePool and ServicesPool.