0
0
GCPcloud~20 mins

Cloud Functions with Pub/Sub triggers in GCP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cloud Functions Pub/Sub Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2:00remaining
What happens when a Cloud Function triggered by Pub/Sub fails?

You have a Google Cloud Function triggered by a Pub/Sub topic. The function processes messages but sometimes throws an error.

What is the behavior of the system when the function fails to process a message?

AThe message is immediately deleted from the Pub/Sub subscription and lost.
BThe message is retried automatically until the function succeeds or the message expires.
CThe message is sent to a dead-letter topic immediately after the first failure.
DThe function stops processing any further messages until the error is fixed.
Attempts:
2 left
💡 Hint

Think about how Pub/Sub handles message delivery guarantees.

Configuration
intermediate
2:00remaining
Which IAM role is required for a Cloud Function to subscribe to a Pub/Sub topic?

You want to deploy a Cloud Function that triggers on messages published to a Pub/Sub topic.

Which IAM role must be granted to the Cloud Function's service account to allow it to receive messages?

Aroles/pubsub.publisher
Broles/pubsub.subscriber
Croles/cloudfunctions.invoker
Droles/pubsub.viewer
Attempts:
2 left
💡 Hint

Consider the permissions needed to pull messages from a subscription.

Architecture
advanced
3:00remaining
Designing a scalable Cloud Function triggered by Pub/Sub for high message volume

You expect a very high volume of messages published to a Pub/Sub topic. You want your Cloud Function to process these messages efficiently without losing any.

Which design approach best supports scalability and reliability?

AUse a single Cloud Function triggered by the Pub/Sub topic with default settings.
BConfigure the Cloud Function with a higher max instances limit and enable concurrency if supported.
CDeploy multiple Cloud Functions each subscribed to the same topic to share the load manually.
DUse a pull subscription and manually poll messages inside the Cloud Function.
Attempts:
2 left
💡 Hint

Think about how Cloud Functions scale automatically and how concurrency affects throughput.

security
advanced
3:00remaining
Securing Cloud Functions triggered by Pub/Sub to prevent unauthorized invocation

You want to ensure that only Pub/Sub can trigger your Cloud Function and no other service or user can invoke it directly.

Which configuration enforces this security requirement?

ASet the Cloud Function to allow unauthenticated invocations.
BGrant the Cloud Function's invoker role to the Pub/Sub service account only.
CDisable authentication on the Cloud Function endpoint.
DUse a firewall rule to block all incoming traffic except from Pub/Sub IPs.
Attempts:
2 left
💡 Hint

Consider how Cloud Functions control who can invoke them.

Best Practice
expert
4:00remaining
Handling message duplication in Cloud Functions triggered by Pub/Sub

Pub/Sub guarantees at-least-once delivery, which means your Cloud Function might receive the same message multiple times.

What is the best practice to handle potential duplicate message processing in your Cloud Function?

AIgnore duplicates because Pub/Sub ensures messages are unique.
BImplement idempotent processing by tracking message IDs and ignoring repeats.
CDelete messages manually from Pub/Sub after processing to avoid duplicates.
DUse a global lock in the Cloud Function to prevent concurrent executions.
Attempts:
2 left
💡 Hint

Think about how to safely handle repeated messages without side effects.