Updated Nov 5, 20265 min read

Cloud Run vs AWS Fargate: Serverless Containers Compared

How Google Cloud Run and AWS Fargate differ on scaling, networking, pricing model and setup, and how to keep the choice reversible.

Google Cloud Run and AWS Fargate both run containers without servers to manage, so they look like direct equivalents. They are built on different ideas. Cloud Run is a request-driven platform with a URL, autoscaling and scale to zero included. Fargate is the compute layer under ECS and EKS, and the load balancer, networking and scaling rules around it are yours to set up.

This comparison covers scaling, networking, billing model and setup for an HTTP backend with a Postgres database. It also shows how Encore (infrastructure from code) deploys the same code to either one, which matters when the choice of cloud is not final.

Cloud Run vs Fargate at a glance

EncoreCloud RunAWS Fargate
What you deployTypeScript or Go codeA container image or sourceA task definition with images
HTTPS entry pointCreated for you on either cloudBuilt-in URL per serviceApplication Load Balancer you add
ScalingCloud Run or Fargate defaults per environmentPer request, down to zeroTarget tracking on CPU, memory or requests
NetworkingPrivate VPC created per environmentGoogle-managed, VPC egress optionalYour VPC, subnets and security groups
Database next to itCloud SQL or RDS from codeCloud SQL you connectRDS you connect
Billing modelCloud usage billed by AWS or GCPPer request or per instance timePer task vCPU and memory time

Each option is covered below, starting with Encore.

Running one codebase on Cloud Run or Fargate with Encore

Encore is infrastructure from code for TypeScript and Go, with a platform that provisions and deploys into your own AWS or GCP account. The same application deploys to Cloud Run on GCP or to Fargate behind an Application Load Balancer on AWS, with rolling deploys, private subnets and an IAM role for each service on both.

Application code passes through Encore and infrastructure guardrails to resources provisioned in your own AWS or GCP account.
Encore provisions the infrastructure your application needs in your own AWS or GCP account.

A service and its database are declared in code, with nothing cloud-specific in it:

// notes/notes.ts import { api, APIError } from "encore.dev/api"; import { SQLDatabase } from "encore.dev/storage/sqldb"; // Cloud SQL on GCP, RDS on AWS, a local Postgres under encore run. export const db = new SQLDatabase("notes", { migrations: "./migrations" }); export const get = api( { expose: true, method: "GET", path: "/notes/:id" }, async ({ id }: { id: number }): Promise<{ id: number; body: string }> => { const row = await db.queryRow<{ id: number; body: string }>` SELECT id, body FROM notes WHERE id = ${id}`; if (!row) throw APIError.notFound("note not found"); return row; }, );

The migration in notes/migrations creates the notes table the queries use:

-- notes/migrations/1_create_notes.up.sql CREATE TABLE notes ( id BIGSERIAL PRIMARY KEY, body TEXT NOT NULL );

On GCP, that becomes a Cloud Run service connected to Cloud SQL in a dedicated project. On AWS, it becomes a Fargate service that receives traffic through an Application Load Balancer and connects to RDS. Which one an environment uses is a setting on the environment, so a team can start on one cloud and add an environment on the other without touching the application. encore run starts Postgres locally and serves the same API before either cloud is involved.

For teams where coding agents write much of the backend, that split keeps agents in application code: they never edit task definitions or Cloud Run YAML, and the deployment target stays a decision people make.

The deployment guide covers the push-to-deploy flow, and environments explains how one app can run on Cloud Run in one environment and on Fargate in another.

Get started
brew install encoredev/tap/encore &&
encore app create
Copy

Run in your terminal to get started locally.

Cloud Run: request-driven containers

Cloud Run takes a container image, or source code it builds for you, and returns an HTTPS URL. Instances are added as requests arrive and removed when traffic stops, down to zero unless you set a minimum. Each instance handles many requests at once, up to a concurrency setting that defaults to 80.

In that model, a service that scales to zero has cold starts on the first request. By default, CPU is only allocated while requests are being handled, so background work after a response needs instance-based billing or a separate Cloud Run job. Reaching private resources like Cloud SQL over private IP or Memorystore needs Direct VPC egress configured.

AWS Fargate: tasks you define

Fargate runs ECS tasks or EKS pods without EC2 instances to manage. For an HTTP service on ECS, you write a task definition with CPU, memory, image and environment, create an ECS service with a desired count, place it in VPC subnets with security groups, and put an Application Load Balancer in front of it. Autoscaling is a separate target tracking policy on CPU, memory or ALB request count.

Tasks run continuously at the count you set. There is no scale to zero on incoming requests, and you pay for each running task's vCPU and memory per second, per Fargate pricing, plus the load balancer. In exchange, there are no request timeouts or CPU throttling between requests, so long-running workers, WebSocket servers and queue consumers fit naturally.

Good to know

Neither service includes a database. On Cloud Run, the connection to Cloud SQL is a flag or a connector; on Fargate, RDS sits in the same VPC and the security groups decide who can reach it. Either way, the database is usually the bigger part of the setup and of the bill.

How to choose

Pick Encore when you want to write the backend once and run it on Cloud Run or Fargate in your own account, with the database, networking and IAM created from the code and the option to change clouds per environment.

Pick Cloud Run for HTTP services with uneven traffic, where scale to zero and a built-in URL save the most setup. Pick Fargate when the rest of your stack is on AWS, when services need to run continuously, such as workers and WebSocket servers, or when you need the VPC-level control of ECS.

Frequently asked questions

What is the difference between Cloud Run and Fargate?

Cloud Run is a request-driven container platform: it gives each service an HTTPS URL, scales instances on incoming requests and can scale to zero. Fargate is a compute engine for ECS tasks and EKS pods: you define tasks, services, a VPC and usually an Application Load Balancer, and tasks keep running at the count you configure or that autoscaling sets.

Can Fargate scale to zero like Cloud Run?

Not on incoming requests. You can set an ECS service's desired count to zero, but nothing starts a task when a request arrives, so HTTP services on Fargate keep at least one task running.

Can I deploy the same backend to both Cloud Run and Fargate?

Yes, if the application does not hardcode cloud-specific infrastructure. With Encore, you write the backend in TypeScript or Go with declarations like new SQLDatabase("notes", { migrations: "./migrations" }), and Encore deploys it to Cloud Run with Cloud SQL on GCP or to Fargate with RDS on AWS from the same code.

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.

~/orders — claude
Claude Code
Claude Code v2.1.180Opus 5.5~/orders