Cloud Run, GKE, Pub/Sub and authentication for the Professional Cloud Developer exam: decision tables
Most Professional Cloud Developer questions come down to three decisions: where the code runs (Cloud Run, GKE or Compute Engine), how components talk (sync or async; Pub/Sub, Eventarc, Cloud Tasks, Workflows), and how code authenticates to Google Cloud services (service accounts, ADC, Workload Identity Federation, Secret Manager). This article turns those decisions into quick-reference tables with practice questions.
Key takeaways
- Most PCD questions revolve around three decisions: where the code runs, how components talk to each other, and how code authenticates to Google Cloud services.
- A stateless container answering HTTP that should scale to zero with low operations points to Cloud Run; sidecars, a service mesh or StatefulSets point to GKE; software that needs a full OS points to Compute Engine.
- To control the call rate to an endpoint, Cloud Tasks has per-queue rate limits while Pub/Sub does not; Pub/Sub handlers must be idempotent because messages can be duplicated.
- Don't keep secrets in hard-coded environment variables or in the image; use Secret Manager.
Choosing a runtime
| Platform | Choose when | Poor fit when |
|---|---|---|
| Cloud Run (service) | Stateless containers serving HTTP, gRPC or events; scale to zero, low ops; deploy from source | You need node access, long-running non-HTTP protocols, detailed Kubernetes configuration |
| Cloud Run functions (formerly Cloud Functions) | Small code responding to events (a new object in a bucket, a Pub/Sub message, HTTP) | Large apps with many routes or needing container control |
| Cloud Run jobs | Run-to-completion tasks (batch, migrations, file processing) that don't serve requests | Services that must always accept requests |
| GKE (Autopilot or Standard) | Many microservices needing Kubernetes features: sidecars, service mesh, StatefulSets, network policies, HPA on custom metrics | Small teams, simple apps, minimal ops |
| Compute Engine | Software needing a full OS, machine-bound licenses, legacy apps not yet containerized | New cloud-native apps |
Cloud Run settings that come up
- Concurrency: concurrent requests per instance; raise it to save money, lower it if the code isn't thread-safe.
- Minimum instances: reduce cold starts for latency-sensitive services at the cost of idle spend.
- Ingress and authentication: restrict ingress to internal, require IAM (the Cloud Run Invoker role) for service-to-service calls.
- Revisions and traffic: deploy a new revision with no traffic, shift percentages gradually; roll back by sending traffic to the old revision.
- VPC access: Direct VPC egress to reach private-IP resources such as Cloud SQL or Memorystore.
Release strategies
| Strategy | Cloud Run | GKE |
|---|---|---|
| Rolling update | By default all traffic moves to the new revision when it's ready | Deployment RollingUpdate with maxSurge/maxUnavailable (practice question #20) |
| Canary | Send a small share of traffic to the new revision (question #9) | Two Deployments behind one Service, or weighted routing via Gateway/service mesh |
| Blue/green | Tag the new revision, switch 100% after testing | Two environments, switch the Service selector |
| A/B testing | Percentage splits between revisions | Header- or weight-based routing |
Async integration: which service
| Service | Model | Use when |
|---|---|---|
| Pub/Sub | Publish/subscribe, many subscribers, at-least-once | Decoupling producers and consumers, fan-out, high-volume event streams |
| Eventarc | Routes events from Google Cloud services (audit logs or direct events) to Cloud Run, GKE, Workflows | "When a bucket, object or record is created, call a service" (question #378) |
| Cloud Tasks | A task queue delivering to a specific handler with rate and retry control | Rate limiting, scheduling individual tasks, calling rate-limited external APIs |
| Workflows | Orchestrates multi-step flows with conditions, waits and error handling | Multi-service processes that need ordering and state |
| Cloud Scheduler | Managed cron | Periodic HTTP calls or Pub/Sub publishes |
Pub/Sub points to remember
- Push vs pull: push sends HTTP to an endpoint such as Cloud Run; pull lets consumers fetch at their own pace.
- At-least-once: messages can be redelivered, so handlers must be idempotent; exactly-once delivery is available only for pull subscriptions.
- Ordering keys: preserve order for messages with the same key.
- Dead-letter topics: move repeatedly failing messages aside for later handling.
For a UI calling a slow third-party API, calling it asynchronously and hiding the result widget on timeout keeps the page responsive (question #26).
Authentication and secrets
| Need | Recommended approach |
|---|---|
| Code on Google Cloud calling Google APIs | Attach a dedicated service account to the resource and use Application Default Credentials; grant the narrowest role (question #42) |
| GKE Pods calling Google APIs | Workload Identity Federation for GKE (Kubernetes service accounts mapped to IAM permissions) |
| Code outside Google Cloud (AWS, Azure, external CI) | Workload Identity Federation instead of JSON keys |
| Local development | gcloud auth application-default login so ADC uses your account |
| Database passwords, API keys | Secret Manager with versions and rotation; mount into Cloud Run as env vars or volumes |
| Connecting to Cloud SQL, AlloyDB | Cloud SQL Auth Proxy or AlloyDB Auth Proxy (or language connectors), IAM database authentication |
| Temporary access to a private file for a user | Time-limited Cloud Storage signed URLs |
| Protecting an internal web app | Identity-Aware Proxy |
| End users signing in to your app | Identity Platform (OAuth 2.0, OpenID Connect, JWT) |
Choosing data stores as a developer
- User state and flexible profiles: Firestore (question #37).
- Images and static files at low cost and latency: Cloud Storage behind Cloud CDN (question #38).
- Caching read-heavy data: Memorystore for Redis.
- Relational transactions: Cloud SQL, AlloyDB; global and strongly consistent means Spanner.
- Analytics: write to BigQuery (streaming or batch).
Common traps
- Using Pub/Sub when you need to control the call rate to one endpoint: Cloud Tasks has per-queue rate limits.
- Non-idempotent Pub/Sub handlers: duplicates get processed twice.
- Using the Compute Engine default service account with Editor: violates least privilege.
- Hard-coding secrets in env vars or images: use Secret Manager.
Start practicing
Try the 60 free Professional Cloud Developer questions, then a timed exam (Pro). For the exam overview, see the Professional Cloud Developer study guide.