Google Professional Cloud Developer Question 439
Single answerGoogle Cloud PlatformYou are developing a serverless application on Google Cloud that processes large amounts of data from IoT devices. Each device sends frequent small payloads to your HTTP API hosted on Cloud Run. To optimize performance and reduce costs, you decide to implement request batching. Which of the following approaches would best align with this requirement?
- A
Use a Pub/Sub topic to collect IoT payloads, and configure a Cloud Run service to batch and process messages using a scheduled Cloud Scheduler job.
- B
Directly configure each IoT device to batch its payloads locally before sending them to the Cloud Run API.
- C
Use a Pub/Sub topic to collect IoT payloads and configure a Cloud Dataflow pipeline to batch the messages before sending them to the Cloud Run API.
- D
Implement request batching directly within the Cloud Run service by aggregating incoming payloads and processing them in-memory.
Show answer and explanation
Correct answer: C
Explanation
The recommended approach for batching requests in a Google Cloud environment is to leverage Pub/Sub for message ingestion and Cloud Dataflow for efficient and scalable batch processing. This decouples the batching logic from the Cloud Run service and ensures that the system remains stateless, scalable, and cost-efficient. Other options either introduce unnecessary complexity or violate best practices for serverless application design.
- A. Incorrect.
Using Pub/Sub and Cloud Scheduler for batching is suboptimal for this use case because Cloud Scheduler jobs run at fixed intervals. This approach may lead to delays in processing if the interval is too long or inefficiencies from frequent job executions.
- B. Incorrect.
Configuring IoT devices to batch payloads locally can cause additional complexity and dependencies on the device-side implementation, which is not an ideal practice for scalability or flexibility.
- C. Correct.
Using Pub/Sub to collect payloads and Cloud Dataflow to batch messages before sending them to the Cloud Run API is the best approach. Cloud Dataflow is designed for real-time and batch processing, providing a scalable and efficient way to handle batching without overloading Cloud Run.
- D. Incorrect.
Implementing request batching directly within the Cloud Run service is not recommended as it may lead to scalability issues. Cloud Run services are designed to handle stateless requests, and maintaining in-memory state for batching can violate this principle.