Google Professional Cloud Developer Question 414
Single answerGoogle Cloud PlatformYou are developing a financial application that processes real-time stock price updates. The application must consume messages from a Pub/Sub topic and ensure that the messages are processed exactly once, even in the event of a crash or failure. Which approach should you take to meet this requirement?
- A
Use a Pub/Sub subscription with message acknowledgment and implement a retry mechanism in your application to handle failures.
- B
Use a Pub/Sub subscription with message acknowledgment and set the subscription to retain acknowledged messages for reprocessing.
- C
Use a Pub/Sub subscription with message acknowledgment and enable Dead Letter Topics (DLTs) for failed messages.
- D
Use a Pub/Sub subscription with the 'at-most-once' delivery guarantee to ensure each message is processed exactly once.
Show answer and explanation
Correct answer: A
Explanation
To ensure exactly-once processing of messages in Google Cloud Pub/Sub, the application must acknowledge messages after successful processing. This acknowledgment mechanism ensures that Pub/Sub does not redeliver the message. Additionally, implementing a retry mechanism helps handle transient failures and ensures message processing reliability. Other options either do not meet the exactly-once requirement or are focused on different use cases like debugging or deduplication.
- A. Correct.
This is correct. Using a Pub/Sub subscription with message acknowledgment ensures messages are processed exactly once, as the acknowledgment acts as a confirmation to Pub/Sub that the message has been successfully processed. Implementing a retry mechanism helps handle failures and ensures reliability.
- B. Incorrect.
This is incorrect. Retaining acknowledged messages would not ensure exactly-once delivery, as the application would need to handle deduplication, which can lead to complications and additional processing.
- C. Incorrect.
This is incorrect. While Dead Letter Topics (DLTs) help in handling undeliverable messages, they do not guarantee exactly-once processing. They are used for identifying and debugging failed messages.
- D. Incorrect.
This is incorrect. The 'at-most-once' delivery guarantee means messages are delivered at most once, which can result in message loss and does not meet the requirement for exactly-once processing.