あなたのチームは、多数のユーザーからの投票を処理する Web サイトを構築しています。受信票はさまざまなレートで到着します。投票の保存と処理を最適化したいと考えています。あなたは何をするべきか?
正解:D
Pub/Sub is a fully managed, real-time messaging service that allows you to send and receive messages between independent applications. Pub/Sub can handle fluctuating and high-volume data streams, such as votes from a large user population. You can use Pub/Sub to save the incoming votes to a topic, which is a named resource that represents the stream of messages. You can also use Pub/Sub to trigger a Cloud Functions instance to process the votes. Cloud Functions is a serverless platform that runs single-purpose functions in response to events. Cloud Functions can scale automatically based on the demand, and you only pay for the resources you use. You can use Cloud Functions to perform any logic or computation on the votes, such as counting, filtering, aggregating, or storing them.
This option is the best choice for optimizing the storage and processing of the votes, as it provides high scalability, low latency, and low cost. It also requires minimal operational and infrastructure management, as both Pub/Sub and Cloud Functions are fully managed services.
The other options are not correct because they either do not provide the required scalability, performance, or functionality. Option A is not correct because using a dedicated instance to process the incoming votes, and sending the votes directly to this instance, is not scalable, as the instance may not be able to handle the variable and high load of the votes. It is also not efficient, as the instance may be underutilized or overutilized at different times. Saving the incoming votes to a JSON file on Cloud Storage, and processing the votes in a batch at the end of the day, is not optimal, as it introduces latency and complexity in the processing. Option B is not correct because saving the incoming votes to Firestore, and using Cloud Scheduler to trigger a Cloud Functions instance to periodically process the votes, is not suitable for high-volume and real-time data streams, such as votes. Firestore is a serverless, NoSQL database that is designed for structured and hierarchical data, not for unstructured and flat data, such as votes. Cloud Scheduler is a fully managed cron job service that allows you to schedule tasks at fixed intervals, not in response to events. Using Cloud Scheduler to trigger Cloud Functions may introduce unnecessary delays and overhead in the processing.
Reference:
Pub/Sub documentation
Cloud Functions documentation
Choosing a storage option
Choosing an event-driven compute platform