Deploying Cloud Run & Cloud Functions
Google ACE ACE · Planning and implementing a cloud solution
Serverless on Google Cloud
Cloud Run and Cloud Functions are Google Cloud's serverless compute services: you deploy code or containers, and Google manages the infrastructure, scaling, and availability. Both scale automatically from zero to thousands of instances, and both bill only for the resources consumed while handling work. The difference is what you deploy and how it is triggered. Cloud Run deploys a container that serves HTTP requests — a web service, an API, a website. Cloud Functions deploys a function — a single unit of code — that runs in response to an event, such as a file upload, a Pub/Sub message, or an HTTP request. Cloud Functions (2nd generation) runs on Cloud Run infrastructure under the hood, which is why the two services share features such as concurrency settings and VPC connectivity.
Deploying to Cloud Run
A Cloud Run deployment starts with a container image stored in Artifact Registry. You deploy it with gcloud run deploy, giving the service a name, the image, and the region — or you can deploy from source code, and Google builds the container for you with buildpacks. Each deployment creates a new revision: an immutable snapshot of the service's code and configuration. Revisions are the key to safe releases: you can split traffic between revisions (for example, 90% to the old revision and 10% to the new one), roll back instantly by shifting traffic to an earlier revision, and pin a revision for testing with a unique URL. The service gets a stable HTTPS URL, and by default it requires authentication — you must explicitly allow unauthenticated access (the run.invoker role for allUsers) if the service should be public.
Cloud Run's scaling settings matter for the exam. Each container instance handles requests with a configurable concurrency (default 80 requests per instance, up to 1,000), and the platform adds instances as traffic grows. Minimum instances keeps a number of instances warm to avoid cold starts, at a cost; maximum instances caps scaling to control cost or protect a downstream database from too many connections. A request can run for at most 60 minutes, and each instance can be given up to 32 GiB of memory and 8 vCPUs. CPU is allocated only while handling requests by default (which is why idle services cost almost nothing), but CPU always allocated is available for workloads that do background work between requests.
Deploying Cloud Functions
A Cloud Function is deployed with gcloud functions deploy, specifying the runtime (such as Python, Node.js, or Go), the entry point (the function to call), and the trigger. The trigger is what makes functions useful: an HTTP trigger turns the function into a small web endpoint, while an event trigger runs it when something happens elsewhere in Google Cloud. Common event sources are Cloud Storage (an object is created, deleted, or archived in a bucket), Pub/Sub (a message arrives on a topic), Firestore (a document is created or changed), and Eventarc, which routes events from many Google Cloud sources (and from custom sources) to Cloud Run or Cloud Functions targets.
Functions are short-lived and stateless: each invocation runs in a fresh environment, and any local state is discarded afterward. The maximum timeout for a 2nd generation function is 60 minutes (9 minutes for 1st generation), and memory can be configured up to 16 GiB. Because invocations can occasionally be retried, functions should be written idempotently — running the same event twice should produce the same result, not a duplicate side effect. That design point appears in exam questions about event-driven architectures: the correct answer often involves idempotency or deduplication, not just the trigger choice.
Choosing where to deploy
The exam guide asks you to determine where to deploy an application using Cloud Run (fully managed), Cloud Run for Anthos (now GKE-based Cloud Run on Google Distributed Cloud — the on-premises and GKE variant), or Cloud Functions. For ACE purposes, the decision is:
| Workload | Deploy to |
|---|---|
| Containerized web service or API, public or internal | Cloud Run (fully managed) |
| Short code triggered by an event (Storage, Pub/Sub, Firestore) | Cloud Functions |
| Containerized service that must run on your own GKE cluster or on-premises | Cloud Run on GKE / Anthos variant |
| Long-running background processing beyond the request timeout | Not serverless — consider Compute Engine, GKE, or Cloud Run jobs |
One more member of the family is worth knowing: Cloud Run jobs run containers to completion (rather than serving requests), which suits batch tasks — a nightly report generator, a data-processing job — that should run once and stop. Jobs share Cloud Run's serverless scaling and billing, and they can be scheduled with Cloud Scheduler. If a question describes a containerized task that runs on a schedule and then exits, a Cloud Run job is a strong candidate.
Events: Pub/Sub, Storage notifications, and Eventarc
Event-driven design on Google Cloud usually involves Pub/Sub, the asynchronous messaging service: publishers send messages to a topic, and subscribers (including Cloud Functions and Cloud Run services) receive them. Pub/Sub decouples the producer from the consumer — the producer does not wait for processing, and messages are retained until acknowledged. Cloud Storage object change notifications can publish directly to a Pub/Sub topic when objects are created or deleted, which is how a file upload triggers processing. Eventarc is the newer, broader event router: it delivers events from Google Cloud services (including audit-log-based events) and custom sources to Cloud Run and other targets, with filtering and transformation. For the exam, the practical mapping is: a Storage event triggering a function is usually done directly or through Pub/Sub; a complex multi-source event flow points to Eventarc.
Security and connectivity for serverless
Serverless services still need network and identity configuration, and the exam tests the common patterns. Every Cloud Run service and Cloud Function runs as a service account: by default it is the project's default Compute Engine service account, but best practice is a dedicated service account with only the roles the service needs — for example, a function that writes to one Firestore collection should not carry a project-wide Editor role. Ingress settings control who can reach a Cloud Run service: allow all traffic (public), allow only internal traffic (from within the VPC or from other Google Cloud services), or allow only traffic from a load balancer. The internal-only setting is the answer when a service should be reachable only by other services in the same project or VPC.
For outbound connectivity, Cloud Run services and functions run outside your VPC by default, so reaching a private resource — a Cloud SQL instance with only a private IP, or a VM in your VPC — requires a VPC connector (a Serverless VPC Access connector) that bridges the serverless environment into the VPC. The connector is a small piece of infrastructure with its own subnet and scaling settings, and it is the standard answer to "my Cloud Run service cannot reach my private database". The exam pairing is worth memorizing: private database plus serverless service equals VPC connector. Without it, the serverless service can only reach public endpoints.
Exam traps to watch for
- Using Cloud Functions for a long-running web service: functions are for short event-driven tasks; Cloud Run is for services.
- Forgetting that Cloud Run services are private by default: public access needs an explicit unauthenticated-invoker grant.
- Treating a revision as editable: revisions are immutable snapshots; changes create a new revision.
- Designing an event-driven function without idempotency: retries can deliver the same event twice.
Practice questions
Test yourself on this guide. Answers are checked instantly, with a full explanation for each question.
Q1.A developer deploys a Cloud Run service and shares its URL with a customer, but the customer gets a 403 Forbidden error. The service works when the developer tests it. What is the most likely cause?
Explanation: Cloud Run services are private by default — only authenticated callers with the run.invoker role can reach them. The developer is authenticated, so it works for them; the customer is not. Allowing unauthenticated invocations (granting run.invoker to allUsers) makes the service public. Region, image size, and minimum instances do not produce a 403 for one caller and not another.
Exam objective: ACE exam guide 2.1: Planning and implementing compute resources — deploying an application
Q2.A team wants to deploy a new version of a Cloud Run service to 10% of users first, and roll back instantly if errors appear. How should they do this?
Explanation: Each Cloud Run deployment creates an immutable revision, and traffic can be split between revisions in any proportion — 10% to the new revision for a canary, with an instant rollback by shifting traffic back to the old revision. A separate service with a DNS change is slower and harder to roll back. Deleting the old revision removes the rollback target. Instance counts control scaling, not traffic routing.
Exam objective: ACE exam guide 2.1: Planning and implementing compute resources — deploying an application
Q3.A company wants a thumbnail generated automatically whenever a user uploads a photo to a Cloud Storage bucket. Which is the simplest design?
Explanation: A Cloud Function with a Storage trigger runs automatically on each object creation — event-driven, serverless, and no polling. A polling Cloud Run service wastes money and adds latency. An hourly CronJob delays thumbnails by up to an hour and needs a cluster. A watcher VM must be managed and paid for continuously.
Exam objective: ACE exam guide 2.1: Planning and implementing compute resources — deploying an application for receiving Google Cloud events
Q4.An order-processing system publishes a message to Pub/Sub for each new order. A function processes each message and charges the customer. Occasionally a message is delivered twice. What property must the function have to avoid double-charging?
Explanation: Pub/Sub delivers messages at least once, so duplicates are possible by design; the consumer must handle them. An idempotent function — for example, one that records processed message IDs and skips duplicates — produces the same result whether it runs once or twice. Limiting instances does not prevent redelivery. The timeout and the region are unrelated to duplicate delivery.
Exam objective: ACE exam guide 2.1: Planning and implementing compute resources — deploying an application for receiving Google Cloud events (Pub/Sub events)
Q5.A team needs to run a containerized report generator once a night. It runs for 20 minutes and then exits. Which service is the best fit?
Explanation: Cloud Run jobs run containers to completion rather than serving requests, and Cloud Scheduler can trigger them on a schedule — a serverless fit for a nightly batch task. A Cloud Run service with a minimum instance would run (and bill) continuously for a 20-minute nightly task. An HTTP-triggered function would need something to call it and is not designed around containers. A GKE Deployment keeps replicas running permanently.
Exam objective: ACE exam guide 2.1: Planning and implementing compute resources — determining where to deploy an application by using Cloud Run or Cloud Functions
Q6.A Cloud Run service connects to a Cloud SQL database that allows at most 100 simultaneous connections. During traffic spikes, the service scales up and the database starts rejecting connections. What should you configure?
Explanation: A maximum instance count caps how many container instances can run, which bounds the number of database connections the service can open. Raising the minimum instance count would make the problem worse by keeping more instances (and connections) alive. Cloud CDN caches HTTP responses and does not affect database connections. Raising concurrency lets each instance handle more requests, but it does not cap the total number of instances — the service can still scale out and exhaust the database.
Exam objective: ACE exam guide 2.1: Planning and implementing compute resources — deploying an application
Q7.A company wants to route events from several Google Cloud services — including audit log events — to a Cloud Run service, with filtering on event type. Which service should they use to route the events?
Explanation: Eventarc is Google Cloud's event router: it delivers events from many Google Cloud sources (including audit logs) and custom sources to Cloud Run and other targets, with filtering on event attributes. Cloud Scheduler triggers work on a time schedule, not on events. Cloud Tasks is a task queue for asynchronous work, not an event router. Cloud Monitoring observes metrics and logs; it does not route events to services.
Exam objective: ACE exam guide 2.1: Planning and implementing compute resources — deploying an application for receiving Google Cloud events (Eventarc)
Q8.A developer wants to deploy a Python function that runs when a message arrives on a Pub/Sub topic. Which command deploys it?
Explanation: gcloud functions deploy creates a Cloud Function, with the runtime and trigger specified as flags — here a Pub/Sub topic trigger. gcloud run deploy deploys Cloud Run services, not functions. kubectl applies Kubernetes manifests. gcloud compute instances create launches VMs, which is unrelated to functions.
Exam objective: ACE exam guide 2.1: Planning and implementing compute resources — deploying an application for receiving Google Cloud events (Pub/Sub events)