Skip to content

Professional Cloud Developer · Domain 4: Integrating applications with Google Cloud services · 21% of the exam

Task 4.1: Integrating applications with data and storage services.

Managing connections to Cloud SQL, Firestore and Cloud Storage, reading and writing data, and publishing and consuming messages.

Study it

  • Connecting to Cloud SQL, Firestore and Cloud Storage, and reading and writing data

    Lesson coming

  • Publishing and consuming messages with Pub/Sub

    Partly covered by: Message Queues

Sample questions

Try each one before opening the answer. Every option is explained, with the Google Cloud documentation page that proves it.

Question 1 · choose 1

A Cloud Run service runs with a concurrency of 250 requests per instance. Each request checks out one connection from this SQLAlchemy pool for the service's Cloud SQL for MySQL database: pool = sqlalchemy.create_engine( url, creator=getconn, pool_size=100, max_overflow=50, pool_timeout=30) Under heavy load, busy instances start failing to open new database connections, and the affected requests return errors. Requests may wait briefly for a pooled connection. What should the team change?

  1. ALower the service's concurrency to 150, so that every request in an instance can hold its own pooled connection
  2. BSet pool_size to 80 and lower max_overflow to 20
  3. CSet pool_size to 90 and keep max_overflow at 50
  4. DRaise pool_timeout to 120 so that requests wait longer for a connection
Show the answer and why
  • ALower the service's concurrency to 150, so that every request in an instance can hold its own pooled connection

    Incorrect

    With 150 requests each holding a connection, an instance still tries to open more than the 100 connections that each Cloud Run instance may have.

  • BSet pool_size to 80 and lower max_overflow to 20

    Correct

    The pool can then hold at most 100 connections, which is the limit for each Cloud Run instance.

  • CSet pool_size to 90 and keep max_overflow at 50

    Incorrect

    The pool can still exceed pool_size by max_overflow, up to 140 connections, above the 100 that an instance may have.

  • DRaise pool_timeout to 120 so that requests wait longer for a connection

    Incorrect

    pool_timeout only sets how long a request waits for a pooled connection; the pool still tries to open connections beyond the instance's limit.

Cloud Run container instances are limited to 100 connections to a Cloud SQL database, and the total grows with the number of instances. A SQLAlchemy pool keeps up to pool_size connections and temporarily exceeds that by up to max_overflow, so its total is pool_size plus max_overflow. A pool of 100 plus 50 therefore asks a busy instance for more connections than it may open. A pool whose total is at most 100 keeps each instance within the limit, and the remaining requests wait for a pooled connection.

Question 2 · choose 1

A ticket service reserves seats with a Firestore transaction in Python: @firestore.transactional def reserve(transaction, seat_ref, user): seat = seat_ref.get(transaction=transaction) if seat.get("holder") is None: transaction.update(seat_ref, {"holder": user.id}) send_confirmation_email(user, seat.id) During busy sales, some buyers receive two or three confirmation emails for one seat. What should the team change?

  1. AReplace the transaction with a batched write of the update
  2. BSend the email before calling transaction.update, so that it goes out only once
  3. CSend the email after reserve returns, only when the transaction has committed with the user as holder
  4. DRead the seat outside the transaction and keep the email inside it
Show the answer and why
  • AReplace the transaction with a batched write of the update

    Incorrect

    A batched write doesn't read the seat first, so it can't check that the seat is still free.

  • BSend the email before calling transaction.update, so that it goes out only once

    Incorrect

    Any statement in the function runs again whenever Firestore runs the transaction again.

  • CSend the email after reserve returns, only when the transaction has committed with the user as holder

    Correct

    A transaction function might run more than once, and it shouldn't modify application state.

  • DRead the seat outside the transaction and keep the email inside it

    Incorrect

    The transaction then no longer protects the read, and the email still runs on every attempt.

In a Firestore transaction, a concurrent edit to a document the transaction reads makes Firestore run the entire transaction again, so the transaction function might run more than once; the client libraries retry transactions that fail because of contention. Transaction functions therefore shouldn't directly modify application state; side effects such as emails belong after the transaction has succeeded. Reads must come before writes in a transaction.

Question 3 · choose 1

A pull subscriber with message ordering enabled updates account balances. For ordering key acct-17 its log shows: 10:00:01 received m1 ack 10:00:02 received m2 ack 10:00:03 received m3 ack 10:00:41 received m2 10:00:41 received m3 m3 had already been applied, and applying it again changed the balance. What explains the log, and what should the team do?

  1. ARedelivery of m2 also redelivered m3, as ordering allows; make the handler skip messages already applied
  2. BThe publisher sent m2 and m3 twice after a timeout; turn on exactly-once delivery in the publishing client
  3. COrdering broke for acct-17; remove the ordering key so that messages arrive one at a time
  4. DThe acks for m2 and m3 were lost; ack each message twice to be safe
Show the answer and why
  • ARedelivery of m2 also redelivered m3, as ordering allows; make the handler skip messages already applied

    Correct

    With ordering, a redelivery of one message triggers redelivery of all later messages for that key, even acknowledged ones.

  • BThe publisher sent m2 and m3 twice after a timeout; turn on exactly-once delivery in the publishing client

    Incorrect

    The pattern matches ordered redelivery on the subscription side, not a repeated publish.

  • COrdering broke for acct-17; remove the ordering key so that messages arrive one at a time

    Incorrect

    Ordering held: m2 arrived again before m3, as within-key ordering expects.

  • DThe acks for m2 and m3 were lost; ack each message twice to be safe

    Incorrect

    Acknowledging twice doesn't stop the later messages of a key from coming back after an earlier one is redelivered.

Pub/Sub delivers each message at least once. With message ordering, a redelivery of one message, for example because its acknowledgment deadline expired or its acknowledgment didn't persist, triggers redelivery of all subsequent messages for that ordering key, even acknowledged ones. A subscriber that changes state must therefore handle repeated messages safely.

Google Cloud documentation

Question 4 · choose 1

A publisher sends account events with ordering keys through the Pub/Sub client library. After a brief network outage, one publish for key acct-17 failed. Since then, every new publish for acct-17 fails at once, while other keys publish normally. What should the code do?

  1. ARecreate the topic so that the key's state is cleared
  2. BResume publishing for acct-17 in the client, then publish the failed message again
  3. CPublish acct-17's messages without an ordering key from now on
  4. DRaise the publisher's batch size so that the failed message goes out with the next batch
Show the answer and why
  • ARecreate the topic so that the key's state is cleared

    Incorrect

    The failed state is in the publisher client for that key, not in the topic.

  • BResume publishing for acct-17 in the client, then publish the failed message again

    Correct

    After an ordered publish fails, queued and future publishes of that key fail until publishing is resumed for it.

  • CPublish acct-17's messages without an ordering key from now on

    Incorrect

    The events of that account would lose their order, which the design needs.

  • DRaise the publisher's batch size so that the failed message goes out with the next batch

    Incorrect

    Batch settings don't clear the failed state of an ordering key.

When publishing with an ordering key fails, the queued messages of the same key in the publisher fail, including future publish requests for that key. The application must resume publishing with the ordering key after such a failure, as the client libraries' samples show.

Question 5 · choose 1

An application on GKE will connect to a Cloud SQL for MySQL instance through the Cloud SQL Auth Proxy, which Google recommends even with private IP. How does the Cloud SQL page say to run the proxy for the application?

  1. AAs a sidecar container in the same Pod, reached by the app on localhost
  2. BAs one Deployment for the whole cluster, reached through a Service
  3. COn a separate Compute Engine VM that the Pods reach over the network
  4. DInside the Cloud SQL instance, enabled with a database flag
Show the answer and why
  • AAs a sidecar container in the same Pod, reached by the app on localhost

    Correct

    The proxy is added to the Pod with the sidecar pattern, so the app connects to it on localhost.

  • BAs one Deployment for the whole cluster, reached through a Service

    Incorrect

    The documented pattern places the proxy in the same Pod as the app.

  • COn a separate Compute Engine VM that the Pods reach over the network

    Incorrect

    The page runs the proxy next to the app inside its Pod.

  • DInside the Cloud SQL instance, enabled with a database flag

    Incorrect

    The proxy runs on the client side, next to the application.

On GKE, Google recommends the Cloud SQL Auth Proxy, even with private IP, because it provides strong encryption and authentication. The proxy is added to the Pod using the sidecar container pattern: it runs in the same Pod as the application, which connects to it on localhost.

Question 6 · choose 1

An upload tool sends large files to Cloud Storage as parallel composite uploads. A downstream job verifies every object against its MD5 hash and now rejects the composed files. What should the downstream job do?

  1. AWait until Cloud Storage computes the MD5 hash after composition
  2. BVerify the objects with their CRC32C checksum instead
  3. CRequest the MD5 hash with a metadata-only download
  4. DDownload each composed object again before checking it
Show the answer and why
  • AWait until Cloud Storage computes the MD5 hash after composition

    Incorrect

    A composite object has no MD5 hash at all.

  • BVerify the objects with their CRC32C checksum instead

    Correct

    A composite object has only a crc32c hash, not an MD5 hash.

  • CRequest the MD5 hash with a metadata-only download

    Incorrect

    There is no MD5 hash to return for a composite object.

  • DDownload each composed object again before checking it

    Incorrect

    A new download returns the same composite object, which still has no MD5 hash.

A parallel composite upload splits a file into parts that are uploaded in parallel and then composed into one object. The resulting composite object has only a crc32c hash and not an MD5 hash, so clients that check objects must use CRC32C.

Question 7 · choose 1

A Pub/Sub subscription feeds a quarterly reconciliation job and has no subscriber activity between runs. Before the second run, the team finds the subscription gone. Which setting prevents this?

  1. ASet the expiration period to never expire
  2. BA message retention duration of 31 days
  3. CA dead-letter topic attached to the subscription
  4. DExactly-once delivery on the subscription
Show the answer and why
  • ASet the expiration period to never expire

    Correct

    By default a subscription expires after 31 days without activity.

  • BA message retention duration of 31 days

    Incorrect

    Retention keeps messages longer; it doesn't stop the subscription from expiring.

  • CA dead-letter topic attached to the subscription

    Incorrect

    A dead-letter topic takes undeliverable messages; it doesn't keep the subscription alive.

  • DExactly-once delivery on the subscription

    Incorrect

    Delivery guarantees don't keep an inactive subscription from expiring.

A subscription's expiration period defaults to 31 days: a subscription without activity for that long is deleted. To keep a rarely used subscription, set the expiration period to never expire. Retention and dead-letter topics govern messages, not the subscription itself.

Practice domain 4 →Practice all domains →