Google Cloud Professional Cloud Developer — Question 230
You are developing an event-driven application. You have created a topic to receive messages sent to Pub/Sub. You want those messages to be processed in real time. You need the application to be independent from any other system and only incur costs when new messages arrive. How should you configure the architecture?
Answer options
- A. Deploy the application on Compute Engine. Use a Pub/Sub push subscription to process new messages in the topic.
- B. Deploy your code on Cloud Functions. Use a Pub/Sub trigger to invoke the Cloud Function. Use the Pub/Sub API to create a pull subscription to the Pub/Sub topic and read messages from it.
- C. Deploy the application on Google Kubernetes Engine. Use the Pub/Sub API to create a pull subscription to the Pub/Sub topic and read messages from it.
- D. Deploy your code on Cloud Functions. Use a Pub/Sub trigger to handle new messages in the topic.
Correct answer: D
Explanation
The correct answer is D because deploying on Cloud Functions allows for automatic scaling and incurs costs only when messages are processed, fulfilling the requirement for real-time processing and independence. Option A is incorrect as Compute Engine does not provide the same level of cost efficiency for event-driven architectures. Option B is not ideal since a pull subscription contradicts the need for real-time processing with a trigger. Option C, while feasible, does not meet the same cost efficiency and simplicity that Cloud Functions provide.