--- title: GCP description: Run a Rivet control plane on Compute Engine, and pools of nodes on Cloud Run or Compute Engine. --- Host your Durable Objects in your Google Cloud project, and the control plane runs on Compute Engine instances across zones. Your pools run on a Cloud Run worker pool or on Compute Engine, and any Cloud Run service calls the rooms by name. ```typescript title="src/cluster.ts" import * as RivetGCP from "@alchemy.run/rivet/GCP"; import * as Layer from "effect/Layer"; export const Cluster = RivetGCP.ComputeEngineControlPlane("Rivet"); export const Default = RivetGCP.CloudRunPool("Default").pipe(Layer.provide(Cluster)); ``` Install `@alchemy.run/gcp` and finish [GCP setup](/gcp/setup). ## The control plane You get three instances across zones. Each has a persistent disk, and they share a Cloud Storage bucket. A Cloud Run service serves them over HTTPS at a `run.app` address, reaching them through a Serverless VPC Access connector, so the instances take no traffic from outside their network and you need no domain. ```typescript title="src/cluster.ts" export const Cluster = RivetGCP.ComputeEngineControlPlane("Rivet", { instances: 3, machineType: "e2-standard-2", diskSize: 20, }); ``` ## On Cloud Run `CloudRunPool` runs nodes on a Cloud Run worker pool: ```typescript title="src/cluster.ts" export const Default = RivetGCP.CloudRunPool("Default", { replicas: 2, cpu: "1", memory: "1Gi", }).pipe(Layer.provide(Cluster)); ``` Nodes can read their secrets from Secret Manager, run as a service account of your own, and reach a control plane at a private address through a VPC network. To move actors off old nodes on a deploy, give each deploy a higher `version` and set `drainOnVersionUpgrade`: ```typescript title="src/cluster.ts" export const Default = RivetGCP.CloudRunPool("Default", { replicas: 2, network: "private", subnetwork: "private-us-central1", env: { RIVET_ENDPOINT: "http://10.0.0.2:6420" }, version: 42, secrets: { RIVET_TOKEN: "projects/acme/secrets/rivet-token/versions/1" }, drainOnVersionUpgrade: true, actorEvictionPeriod: 60, }).pipe(Layer.provide(Cluster)); ``` On a [private control plane](#reach-a-private-control-plane), the nodes join its network and connect to the private address, with no `network` or `env` of your own. A `subnetwork` you name is used in that network. A `network` you name keeps the nodes off it, and they connect to the control plane's `endpoint`. The nodes run as the worker pool's own service account unless you name one, and that account is granted each secret before a revision reads it. The control plane's token reaches the nodes the same way, from a secret the pool keeps, so it never appears in the worker pool's configuration. Cloud Run holds a private network's addresses for up to a few hours after the pool is deleted, so a destroy in that window fails on the subnetwork, keeps it in state, and succeeds when run again later. ## On Compute Engine `ComputeEnginePool` runs one Compute Engine instance per node: ```typescript title="src/cluster.ts" export const Default = RivetGCP.ComputeEnginePool("Default", { replicas: 2, machineType: "e2-small", }).pipe(Layer.provide(Cluster)); ``` Each deploy updates running nodes in place, one at a time. A node restarts only once the node before it runs the new program and the control plane lists every node connected again, and it gets `stopTimeout` seconds (default 30) to drain before it is killed. A node still waiting after `rolloutTimeout` seconds (default 600) keeps its current program, so a program that never connects stops the rollout at its first node. The control plane's token reaches the nodes from Secret Manager, never instance metadata. ## Reach a private control plane On a [`Rivet.ControlPlane`](/rivet/control-planes#reach-it-at-a-private-address) with a private address, `network` is the subnetwork that address is on. `CloudRunPool` and `ComputeEnginePool` run their nodes in it, in its region: ```typescript network: RivetGCP.Network(GCP.Compute.Subnetwork.lookup({ subnetworkName: "rivet" })), ``` ## Rivet Services `ServicesPool` runs [Rivet Services](/rivet/durable-streams) on a Cloud Run worker pool: ```typescript title="src/cluster.ts" export const Services = RivetGCP.ServicesPool("Services").pipe(Layer.provide(Cluster)); ``` Cloud Run pulls its image from Docker Hub through an Artifact Registry remote repository, which the pool creates. ## Call it from Cloud Run ```typescript title="src/api.ts" export default class Api extends GCP.Run.Service()( "Api", { main: import.meta.url, invokerIamDisabled: true }, 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: [ComputeEngineControlPlane](/providers/rivet/gcp#computeenginecontrolplane), [CloudRunPool](/providers/rivet/gcp#cloudrunpool), [ComputeEnginePool](/providers/rivet/gcp#computeenginepool) and [ServicesPool](/providers/rivet/gcp#servicespool).