You have a Cloud Function triggered by a Pub/Sub topic. The function processes messages but sometimes throws an error during execution.
What is the behavior of Pub/Sub and the Cloud Function when an error occurs?
Think about how Pub/Sub handles message acknowledgment and retries.
When a Cloud Function triggered by Pub/Sub throws an error, the message is not acknowledged. Pub/Sub retries delivering the message until the function succeeds or the message expires based on the subscription's ack deadline and retention policy.
You want to deploy a Cloud Function that triggers when messages are published to a specific Pub/Sub topic.
Which IAM role should you assign to the Cloud Function's service account to allow this trigger?
Consider which role allows receiving messages from Pub/Sub.
The Cloud Function needs the 'roles/pubsub.subscriber' role to pull messages from the Pub/Sub subscription and be triggered properly.
You need to build a system where Cloud Functions process Pub/Sub messages reliably without losing any messages, even if the function fails temporarily.
Which design choice best ensures message durability and processing reliability?
Think about how to handle failed messages and retries safely.
Configuring a dead-letter topic allows failed messages to be captured for later inspection. Enabling retries on Cloud Functions ensures messages are retried until successful processing, preventing message loss.
You want to secure your Cloud Function triggered by Pub/Sub so that only authorized messages can invoke it.
Which practice best enhances security in this integration?
Consider how to authenticate messages sent to the Cloud Function.
Using a push subscription with an authentication token ensures that only Pub/Sub can invoke the Cloud Function. Verifying the token in the function code adds an extra security layer.
Your system receives a high volume of Pub/Sub messages. You use Cloud Functions to process them, but you notice cold starts and throttling affecting performance.
Which approach best addresses these issues?
Think about alternatives to Cloud Functions that handle scaling better.
Cloud Run provides better control over concurrency and scales smoothly for high-throughput workloads, reducing cold starts and throttling compared to Cloud Functions.