Serverless on Google Cloud: Cloud Run, Cloud Run Functions, App Engine and Choosing the Right Compute
Serverless Means
- No servers to manage: Google handles scaling, patching and capacity
- Scale to zero: no traffic, no cost (for most serverless products)
- Pay per use: request time or resources used
Cloud Run
- Runs any container (any language) that listens for HTTP requests, or runs as a job
- Each service gets an HTTPS URL, automatic scaling and revisions
- Concurrency: one instance can handle many requests at once (default 80), so it is efficient
- Settings: CPU and memory, min instances (avoid cold starts), max instances (protect backends), timeouts
bash
# Build from source and deploy in one step
gcloud run deploy hello --source=. --region=asia-south1 --allow-unauthenticated
# Or deploy an existing image
gcloud run deploy api --image=asia-south1-docker.pkg.dev/my-proj/apps/api:1.0 --region=asia-south1 \
--min-instances=1 --max-instances=20 --concurrency=80 --service-account=api-sa@my-proj.iam.gserviceaccount.com \
--set-secrets=DB_PASSWORD=db-password:latest --no-allow-unauthenticated
| Feature | Use |
|---|---|
| Revisions and traffic splitting | Send 10 percent to a new revision (canary) and roll back instantly |
| Cloud Run jobs | Run to completion (batch, migrations, scheduled with Cloud Scheduler) |
| Authentication | Make services private. Callers need roles/run.invoker |
| VPC access | Direct VPC egress or connector to reach private databases |
| Domain mapping / load balancer | Custom domains, Cloud Armor, CDN |
bash
gcloud run services update-traffic api --region=asia-south1 --to-revisions=api-00002=10,api-00001=90
gcloud run services logs read api --region=asia-south1 --limit=20
Cloud Run Functions
- Short pieces of code triggered by events: an HTTP call, a file in Cloud Storage, a Pub/Sub message, a Firestore change
- Built on Cloud Run, so you also get its scaling and settings
- Good for glue code, small webhooks and automation
python
import functions_framework
@functions_framework.cloud_event
def on_upload(event):
data = event.data
print("New file:", data["bucket"], data["name"])
bash
gcloud functions deploy on-upload --gen2 --runtime=python312 --region=asia-south1 --source=. --entry-point=on_upload \
--trigger-bucket=my-uploads
App Engine
| Standard | Flexible | |
|---|---|---|
| Runs on | Sandbox with supported runtimes | Docker containers on Compute Engine VMs |
| Scale to zero | Yes | No (at least one instance) |
| Start time | Seconds | Minutes |
| Use | Web apps and APIs in common languages | Custom runtimes or background workers |
App Engine is the older PaaS. For new projects, Cloud Run is usually the better choice, but you may meet App Engine in existing systems and exam questions.
Choosing Compute
| Need | Choose |
|---|---|
| Full OS control, lift-and-shift, licensed software | Compute Engine |
| Many microservices, Kubernetes ecosystem | GKE |
| Stateless web app or API in a container, no cluster | Cloud Run |
| Run code on an event with minimal setup | Cloud Run functions |
| Existing App Engine app | App Engine |
| Batch jobs that run to completion | Cloud Run jobs or Batch |
| Run VMs on a physical server for yourself | Sole-tenant nodes |
Practice
- Deploy a hello container to Cloud Run and open its URL
- Split traffic 90/10 between two revisions
- Deploy a function triggered by a Cloud Storage upload
- Make a service private and call it with an identity token
- Decide the best compute for five described apps
Conclusion
Cloud Run is the default serverless choice for containers, functions handle events, and App Engine remains for older apps. Pick GKE for Kubernetes needs and Compute Engine for full control.
Quick Summary: serverless; Cloud Run; functions; App Engine; choosing.

