Serverless
Google Cloud Run
Managed container hosting that autoscales to zero and bills per use.
What it is
Cloud Run runs your Docker container in Google Cloud without managing servers or Kubernetes. It is enough for the container to listen on an HTTP port and be stateless.
It scales from zero to thousands of instances depending on traffic, and with no requests you pay nothing. One instance can handle many requests at once, which is cheaper than the one function, one request model.
There are also Cloud Run jobs for batch tasks. It is a good compromise between FaaS and containers: you are not tied to a function format and the image can move to another host, since Cloud Run is compatible with the Knative API.
Use it when
- A backend or API in a container that must be deployed quickly without Kubernetes.
- Uneven traffic and a wish to pay only for usage.
- You need portability: the same Docker image can run elsewhere.
- Webhooks, internal services and batch jobs.
Avoid it when
- The app keeps state in memory or on disk between requests.
- You need WebSocket connections lasting many hours or general GPU workloads.
- Container cold start latency is unacceptable and keeping minimum instances does not fit the budget.
Key concepts
- Service
- A container that answers HTTP requests, has its own URL and revisions.
- Revision
- An immutable version of a service. Traffic can be split between revisions for a canary release.
- Concurrency
- How many requests one instance handles at once (up to 1000), which lowers instance count and cost.
- Min instances
- A minimum of warm instances to avoid cold starts for a small cost.
- Jobs
- A container that runs to completion without HTTP: migrations, reports, batch processing.
Example
Interview questions
1. How does Cloud Run differ from Cloud Functions or Lambda?
Cloud Run runs an arbitrary container and lets one instance handle many requests at once. Functions accept code in a defined format and usually handle one request per instance.
2. Why must an app on Cloud Run be stateless?
Instances are created and removed automatically, and local disk and memory do not survive between them. State goes to external stores: a database, Redis or Cloud Storage.
3. How do you reduce cold starts?
Set a minimum number of instances, shrink the image, speed up app startup and raise concurrency so new instances start less often.
Related technologies
- Google CloudGoogle's cloud with strong data, analytics, Kubernetes (GKE) and ML services.
- DockerDocker packages an application with its dependencies into a container that runs the same on a laptop, a server and the cloud.
- AWS LambdaAn AWS service that runs functions in response to events and bills only for execution time.
- KubernetesKubernetes is a container orchestration system that deploys, scales and heals applications across a cluster of servers.
- Google Pub/SubGoogle Pub/Sub is a global managed messaging service with a publish/subscribe model that scales automatically.
Logos belong to their owners and are used for identification only. Icons: Simple Icons (CC0), Devicon (MIT).