Google Professional Cloud Developer Question 462
Single answerGoogle Cloud PlatformYou are developing a serverless application on Google Cloud that processes data from a third-party API. The API has strict rate limits, and the data rarely changes during the day. To improve performance and reduce API calls, you decide to implement caching. Which approach would be the most appropriate for caching the API responses in this scenario?
- A
Use Cloud Storage to store the API responses as files and fetch them when needed.
- B
Use Memorystore (Redis) to cache the API responses with a time-to-live (TTL) setting.
- C
Use a Pub/Sub topic to store the API responses and publish them to subscribers when needed.
- D
Use Cloud SQL to store the API responses in a database table and query it when needed.
Show answer and explanation
Correct answer: B
Explanation
Memorystore (Redis) is the most suitable option for caching API responses in this scenario. It provides fast, in-memory caching with support for TTL, which ensures that outdated data is automatically invalidated. This approach reduces API calls, respects rate limits, and improves performance. Other options, while viable for persistent storage or messaging, are not optimized for caching use cases.
- A. Incorrect.
While Cloud Storage can store API responses as files, it is not optimized for fast, frequent lookups and doesn't provide built-in mechanisms like TTL for automatic cache invalidation.
- B. Correct.
Memorystore (Redis) is an in-memory data store that provides low-latency access to cached data. It supports TTL, making it an ideal choice for caching frequently accessed, time-sensitive data like API responses.
- C. Incorrect.
Pub/Sub is designed for messaging and event-driven architectures, not for caching. It is not suitable for storing and retrieving API responses efficiently.
- D. Incorrect.
Cloud SQL can store data persistently, but it is not optimized for caching. Querying a database repeatedly would introduce unnecessary latency compared to an in-memory caching solution.