Google Professional Cloud Developer Question 411
Single answerGoogle Cloud PlatformYou are building a cloud-based application that processes real-time transactions. The application must publish transaction data to a Google Cloud Pub/Sub topic and ensure each message is processed exactly once by a downstream service. How should you configure your application to meet this requirement?
- A
Use a Pub/Sub topic with message ordering enabled and ensure subscribers acknowledge messages after processing.
- B
Use a Pub/Sub topic and configure the subscriber to use pull mode with an at-most-once delivery acknowledgment policy.
- C
Use a Pub/Sub topic with Dead Letter Topics (DLTs) enabled and use a push subscription for downstream processing.
- D
Use a Pub/Sub topic and configure the subscriber to use pull mode with an exactly-once delivery acknowledgment policy.
Show answer and explanation
Correct answer: A
Explanation
To achieve exactly-once processing in a Google Cloud Pub/Sub workflow, you need to configure your application to use message ordering and ensure that subscribers acknowledge messages only after successful processing. This setup ensures that messages are delivered in sequence and not re-delivered unless processing fails, avoiding duplicates. While other options address parts of the problem, they do not fully meet the requirement.
- A. Correct.
Correct. Enabling message ordering ensures that messages are processed in sequence, and requiring subscribers to acknowledge messages after processing ensures at-least-once delivery, which combined can be configured for exactly-once processing downstream.
- B. Incorrect.
Incorrect. Pull mode with an at-most-once delivery acknowledgment policy does not guarantee that every message is processed exactly once. Messages may be lost if not acknowledged properly.
- C. Incorrect.
Incorrect. Dead Letter Topics help manage undeliverable messages but do not inherently ensure exactly-once processing. Additionally, push subscriptions may introduce challenges in ensuring exactly-once processing.
- D. Incorrect.
Incorrect. Pub/Sub does not natively support an exactly-once delivery acknowledgment policy. Subscribers must implement logic to achieve this while ensuring no duplicate processing.