# Free GPCD practice questions

> 10 free GPCD practice questions with the correct answer and an explanation.

Page: https://devopscodelab.com/exams/google-professional-cloud-developer/free-practice-questions/
Practice exams: https://devopscodelab.com/exams/google-professional-cloud-developer/

### Question 1 of 10

A developer must store database passwords and third-party API tokens for a Cloud Run service. Security requires automatic version history, IAM-controlled access per secret, and audit logs of every access. What should the developer use?

- A. Cloud Storage, storing the credentials in a bucket that uses CMEK and uniform bucket-level access for every object
- B. Secret Manager, granting only the service's own service account the Secret Accessor role on each secret
- C. Runtime environment variables set in the Cloud Run service YAML and restricted with the Cloud Run Developer role
- D. Cloud KMS, encrypting each credential with a key and storing the ciphertext as a Cloud Run environment variable

**Answer:** B

**Explanation:** Secret Manager versions every secret, supports IAM bindings on individual secrets, and records access in Cloud Audit Logs; granting the Secret Accessor role only to the service's own service account follows least privilege. Cloud KMS manages keys rather than storing secrets, so the team would have to build versioning and distribution themselves. A CMEK bucket encrypts objects but is not designed for secret versioning and per-secret access workflows. Plain environment variables are visible to anyone who can view the service configuration and have no per-access audit trail.

### Question 2 of 10

A payments API exposed to partners must enforce per-partner quotas, verify API keys, transform legacy SOAP requests into REST calls, and give product managers analytics and a developer portal for onboarding. Which solution should the developer recommend?

- A. API Gateway, with an OpenAPI specification that defines API keys and a quota per consumer project
- B. Apigee, with API products that carry quotas, key verification, and SOAP-to-REST mediation policies
- C. An external Application Load Balancer with Cloud Armor rate-limiting rules keyed on a partner header
- D. Cloud Endpoints with the Extensible Service Proxy V2 deployed as a sidecar next to each backend

**Answer:** B

**Explanation:** Apigee is the full API management platform: API products bundle quotas and key verification, policies can mediate SOAP to REST, and it provides analytics and an integrated developer portal. API Gateway supports API keys and simple quotas but has no protocol mediation or partner-facing developer portal. Cloud Endpoints with ESPv2 offers authentication and monitoring but also lacks mediation and portal capabilities. Cloud Armor rate limiting throttles traffic but does not manage API keys, transform payloads, or provide API analytics.

### Question 3 of 10

A service on GKE calls a Cloud SQL for PostgreSQL instance that has only a private IP. Security requires IAM-based authorization for database connections and encryption in transit, without managing SSL certificates in the application. What should the developer do?

- A. Run the Cloud SQL Auth Proxy as a sidecar using Workload Identity Federation for GKE and IAM database authentication
- B. Expose the instance through a Private Service Connect endpoint and connect with the built-in postgres user and password
- C. Add the GKE node IP ranges to the instance's authorized networks and require SSL connections
- D. Connect directly to the private IP with a database password stored in a Kubernetes Secret

**Answer:** A

**Explanation:** The Cloud SQL Auth Proxy authorizes connections with IAM, encrypts traffic with TLS automatically, and with Workload Identity Federation for GKE uses the pod's mapped identity; IAM database authentication removes static passwords. A direct private IP connection with a password lacks IAM authorization and automatic TLS. Authorized networks apply to public IP and would require managing certificates. A Private Service Connect endpoint provides private reachability but not IAM-based authorization or automatic encryption by itself.

### Question 4 of 10

A team runs integration tests in Cloud Build that need a real PostgreSQL database and a Pub/Sub emulator. The tests must run in isolation for every pull request without touching shared environments. Which approach is BEST?

- A. Point each build at the shared staging Cloud SQL instance and truncate all tables before the integration tests start
- B. Mock every database and Pub/Sub call in unit tests, then skip integration testing in Cloud Build entirely
- C. Run the tests only after deployment to production by adding a smoke test step to the Cloud Deploy pipeline
- D. Run PostgreSQL and the Pub/Sub emulator as detached containers on the cloudbuild network, then run the tests

**Answer:** D

**Explanation:** Cloud Build steps run as containers on a shared Docker network named cloudbuild, so a step can start PostgreSQL and the emulator in detached mode and later steps reach them by name, giving isolated, disposable dependencies per build. A shared staging instance causes interference between concurrent pull requests. Testing only in production finds integration bugs too late. Mocks are useful for unit tests but do not verify real integration behaviour.

### Question 5 of 10

A team wants Gemini Code Assist in their IDE to follow internal conventions, such as the approved logging library and error-handling style, without repeating them in every prompt. What should they do?

- A. Ask each developer to state the conventions at the start of each chat session in the IDE before asking for code
- B. Disable code completion and use only the chat panel so that every answer is reviewed manually
- C. Paste the full style guide into a code comment at the top of every source file in the repository
- D. Add a repository context file listing the conventions, which the assistant includes with requests

**Answer:** D

**Explanation:** Context engineering means supplying persistent, relevant instructions, such as a context or rules file in the repository, so the assistant applies team conventions automatically. Comments in every file add noise and are not a reliable instruction channel. Disabling completion does not teach the assistant the conventions. Repeating conventions per session is error-prone and inconsistent.

### Question 6 of 10

A GKE pod loads a large machine learning model at start-up, which can take up to three minutes. The liveness probe restarts the container before loading finishes. What should the developer add?

- A. A higher initialDelaySeconds on the readiness probe and a lower timeout on the liveness probe
- B. A PodDisruptionBudget with minAvailable set to one so that the pod cannot be restarted early
- C. A readiness probe with a short period so that the pod is removed from Service endpoints while loading
- D. A startup probe whose failureThreshold multiplied by periodSeconds covers at least three minutes

**Answer:** D

**Explanation:** A startup probe holds off liveness and readiness probes until it succeeds, so failureThreshold multiplied by periodSeconds can cover the slow model load without weakening the liveness probe afterwards. A readiness probe keeps traffic away but does not stop liveness restarts. Changing readiness delay and shortening the liveness timeout makes restarts more likely. A PodDisruptionBudget limits voluntary evictions, not kubelet restarts caused by failed probes.

### Question 7 of 10

A Pub/Sub push subscription delivers messages to a Cloud Run service. Processing takes up to eight minutes, and messages are redelivered while the first attempt is still running. What should the developer change?

- A. Increase only the Cloud Run request timeout to 60 minutes, leaving the subscription's ack deadline at its default
- B. Raise the subscription's ack deadline above the processing time, and keep the Cloud Run timeout above it
- C. Enable message ordering, because ordered delivery prevents a message from being sent twice in parallel
- D. Reduce the Cloud Run concurrency to one so that each instance processes only a single push request

**Answer:** B

**Explanation:** For push subscriptions, the ack deadline is how long Pub/Sub waits for an HTTP response before redelivering, so it must exceed processing time (the maximum is 600 seconds), and the Cloud Run timeout must be at least as long. Raising only the Cloud Run timeout still lets Pub/Sub redeliver after the default deadline. Ordering does not prevent redelivery after a deadline expires. Concurrency changes do not stop deadline-based redelivery.

### Question 8 of 10

A Deployment on GKE must be reachable from the internet through HTTPS with a Google-managed certificate and path-based routing to two services. Which approach should the developer use?

- A. A Gateway with a global external Application Load Balancer class, HTTPRoutes, and a managed certificate
- B. A Service of type LoadBalancer for each Deployment, with certificates stored in Kubernetes Secrets and mounted into pods
- C. A Service of type ClusterIP with kubectl port-forward running on a bastion host for users
- D. A Service of type NodePort with firewall rules opening the port to 0.0.0.0/0 on every node

**Answer:** A

**Explanation:** The GKE Gateway controller provisions an Application Load Balancer from Gateway and HTTPRoute resources, supporting path-based routing and Google-managed certificates. A LoadBalancer Service creates a passthrough Network Load Balancer per service, without layer 7 path routing or managed certificates. NodePort exposure is insecure and lacks TLS termination. Port-forwarding is a debugging tool, not production ingress.

### Question 9 of 10

A bug in a subscriber processed the last six hours of Pub/Sub messages incorrectly. The fix is deployed, and the messages were already acknowledged. How can the team reprocess them?

- A. Seek the subscription to a timestamp six hours ago, given message retention covers that window
- B. Increase the ack deadline so that the acknowledged messages are redelivered to the subscriber
- C. Publish the six hours of messages again by reading them back from the subscription's dead-letter topic
- D. Recreate the subscription, which automatically delivers all messages published in the past day

**Answer:** A

**Explanation:** Seeking to a time redelivers retained messages published after that time, provided acknowledged-message retention or topic retention covers the window. A new subscription only receives messages published after it is created, unless it is seeked using topic retention. Successfully processed messages never reach a dead-letter topic. The ack deadline does not affect already acknowledged messages.

### Question 10 of 10

An inventory service consumes Pub/Sub messages. Updates for the same product must be processed in the order they were published, while different products can be processed in parallel. What should the developer configure?

- A. Add a sequence number attribute and sort messages in memory before processing each batch
- B. Enable message ordering on the subscription and publish with the product ID as the ordering key
- C. Enable exactly-once delivery on the subscription, which also preserves publish order
- D. Use a single subscriber with one thread so that all messages are processed one at a time

**Answer:** B

**Explanation:** With ordering enabled and the product ID as ordering key, messages with the same key are delivered in order while different keys proceed in parallel. A single thread serializes everything and kills throughput. Sorting in memory fails across batches and subscriber instances. Exactly-once delivery prevents redelivery after a successful acknowledgement but does not guarantee order.

Ready for a timed run? Take the free 15-question GPCD mini exam: https://devopscodelab.com/app/exams/google-professional-cloud-developer/mini/

DevOpsCode Lab is not affiliated with Google Cloud. GPCD and related names are trademarks of their owners. We write every question ourselves; these are not real exam questions.
