When to run a service on Cloud Run and when on Compute Engine virtual machines, covering scaling, billing, request limits, background work, networking and what you operate yourself.

Cloud Run and Compute Engine both run your code on Google Cloud, and they put the line between you and the platform in different places. Cloud Run takes a container image and gives you an HTTPS endpoint that scales with requests, down to zero. Compute Engine gives you virtual machines with an OS you control, which run whether or not traffic arrives.
For a typical HTTP API, the deciding factors are how traffic arrives, what runs between requests, and what the service needs from the machine. Cloud Run is built for request-driven, stateless services. Compute Engine is the answer when a workload needs a long-lived process, local disk, a non-HTTP protocol, a specific kernel, or steady load at the lowest unit cost.
Cloud Run fits HTTP services and event handlers whose load varies: APIs, webhooks, Pub/Sub push consumers, internal tools. One gcloud run deploy produces an HTTPS endpoint with a managed certificate, revisions with traffic splitting, and scaling based on concurrent requests per instance, which defaults to 80 times the number of vCPUs and can go up to 1,000. With request-based billing, an idle service with no minimum instances costs nothing.
The constraints come from that model. The request timeout defaults to five minutes and maxes out at 60. Under request-based billing, CPU is only allocated while requests are processed, so work that continues after the response is written stalls. The file system is in memory, instances can be stopped at any time, and cold starts add latency to the first request after scaling up unless you keep minimum instances warm.
Compute Engine fits workloads that do not look like requests: a game server on UDP, a long-running stream processor, a database you operate yourself, software licensed per machine, or anything that needs a GPU type, kernel module or local SSD that a managed container platform does not offer. For load that is steady around the clock, VMs with committed use discounts also tend to cost less per vCPU-hour than paying for the same compute on a per-request basis.
The trade is that everything Cloud Run does becomes your configuration. A production setup needs an instance template, a regional managed instance group with an autoscaler and health checks, an external Application Load Balancer with a certificate, OS patching, log and metric agents, and a rollout process for new versions.
Encore is a backend framework with built-in infrastructure. On GCP it deploys each environment to Cloud Run or GKE in your own project, and Encore provisions an IAM role for the service, or a service account on GCP. Secrets come from Secret Manager, along with the Pub/Sub topics, Cloud SQL databases and buckets your code declares. It does not manage standalone Compute Engine VMs.

Run in your terminal to get started locally.
A carrier webhook is a good Cloud Run workload if the handler respects the platform: verify, queue and return, so nothing has to run after the response. The webhook is a raw endpoint, and the key is an Encore secret:
// Service shipping receives carrier webhooks and processes them in the background.
package shipping
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"io"
"net/http"
"encore.dev/pubsub"
)
var secrets struct {
CarrierWebhookKey string
}
type ShipmentEvent struct {
TrackingID string `json:"tracking_id"`
Status string `json:"status"`
}
var shipmentEvents = pubsub.NewTopic[*ShipmentEvent]("shipment-events", pubsub.TopicConfig{
DeliveryGuarantee: pubsub.AtLeastOnce,
})
// Webhook verifies the signature, queues the event and answers within milliseconds.
// The slow part runs in the subscription, not after the response is written.
//
//encore:api public raw method=POST path=/webhooks/carrier
func Webhook(w http.ResponseWriter, req *http.Request) {
body, err := io.ReadAll(io.LimitReader(req.Body, 1<<20))
if err != nil {
http.Error(w, "bad body", http.StatusBadRequest)
return
}
mac := hmac.New(sha256.New, []byte(secrets.CarrierWebhookKey))
mac.Write(body)
want := hex.EncodeToString(mac.Sum(nil))
if !hmac.Equal([]byte(want), []byte(req.Header.Get("X-Signature"))) {
http.Error(w, "bad signature", http.StatusUnauthorized)
return
}
var ev ShipmentEvent
if err := json.Unmarshal(body, &ev); err != nil {
http.Error(w, "bad json", http.StatusBadRequest)
return
}
if _, err := shipmentEvents.Publish(req.Context(), &ev); err != nil {
http.Error(w, "try again", http.StatusServiceUnavailable)
return
}
w.WriteHeader(http.StatusAccepted)
}
The work happens in a Pub/Sub subscription, which retries on error and runs as its own unit of work:
package shipping
import (
"context"
"encore.dev/pubsub"
"encore.dev/rlog"
)
var _ = pubsub.NewSubscription(shipmentEvents, "update-orders",
pubsub.SubscriptionConfig[*ShipmentEvent]{Handler: updateOrder})
func updateOrder(ctx context.Context, ev *ShipmentEvent) error {
// Update the order, notify the customer, and so on. An error retries the event.
rlog.Info("shipment update", "tracking_id", ev.TrackingID, "status", ev.Status)
return nil
}
We ran this app with encore run: a correctly signed webhook returned 202, the subscription logged the delivered status for tracking ID 1Z999, and a request with a wrong signature returned 401.
The same code deploys to Cloud Run on GCP or to Fargate on AWS, and switching an environment to GKE does not change it. A coding agent that adds a second carrier writes a second raw endpoint and publishes to the same topic, without touching a Cloud Run service definition or a load balancer.
Best fit: HTTP APIs and event-driven services on GCP that want Cloud Run, Pub/Sub, Cloud SQL and secrets set up from the code, in their own project.
On Cloud Run, the deploy is one command once the image is in Artifact Registry and the service account and secret exist:
On Compute Engine, the same service needs a template that installs and starts it, a managed instance group and an autoscaler, and then the load balancer pieces in front:
The Pub/Sub topic and subscription, the database, the IAM bindings for the service account and the per-environment copies of all of it are separate in both cases, usually in Terraform.
Best fit: Cloud Run by hand for single services on GCP; Compute Engine for workloads that need VMs.
Start on Cloud Run for HTTP and event-driven services, and keep handlers request-scoped so request-based billing does not stall background work. Move to Compute Engine when you can name what Cloud Run cannot give you, such as UDP, local state, a long-lived process or the lowest cost for flat 24-hour load. Pick Encore when you want Cloud Run and the Pub/Sub, Cloud SQL and secrets around it provisioned from your Go or TypeScript code in your own GCP project.
Cloud Run runs stateless containers that Google scales by request load, including to zero, and you never manage the machines. Compute Engine gives you virtual machines that run until you stop them, with full control over the OS, disks and network, and you handle scaling, patching and load balancing.
Yes. For spiky or low traffic, Cloud Run with request-based billing charges only while instances handle requests, start or shut down, and can scale to zero. For steady high load around the clock, a right-sized VM with committed use discounts can be the better fit. Compare against your traffic pattern.
Yes. With instance-based billing, a Cloud Run job, or by moving the work to a queue such as Pub/Sub so it arrives as its own request. With request-based billing, CPU is only allocated while a request is being processed, so goroutines or threads that keep working after the response stall.
On GCP, Encore deploys services to Cloud Run or to GKE, which you choose per environment, in your own project. It does not manage standalone Compute Engine VMs, though encore build docker produces an image you can run on a VM yourself.
Deploy to your cloud on AWS and Google Cloud
without managing infrastructure
Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.