Google Professional Cloud Developer Question 461
Single answerGoogle Cloud PlatformYou are developing a serverless application on Google Cloud using Cloud Functions to serve frequently accessed data. The data is stored in a Firestore database and is queried on each function invocation. To improve performance and reduce costs, you decide to implement a caching strategy. Which of the following caching solutions is the most appropriate for this scenario?
- A
Use Memorystore for Redis to cache the query results.
- B
Use a global variable in the Cloud Function to store the query results.
- C
Store the query results in a Cloud Storage bucket for later retrieval.
- D
Enable Firestore's built-in caching to serve cached results.
Show answer and explanation
Correct answer: A
Explanation
Caching is a critical performance optimization technique, especially in serverless applications where frequent database queries can lead to high latency and increased costs. Using a managed in-memory cache like Memorystore for Redis provides the required performance and scalability for serving frequently accessed data in real-time. Other options, such as global variables or Cloud Storage, are not suitable for this use case due to their limitations in reliability, latency, or intended usage patterns.
- A. Correct.
Using Memorystore for Redis is the most appropriate solution because it is a managed in-memory data store that provides low latency and high throughput, making it ideal for caching frequently accessed data.
- B. Incorrect.
Using a global variable is not a reliable caching solution in Cloud Functions because the execution environment can scale and reset at any time, causing the cache to be lost.
- C. Incorrect.
Cloud Storage is not designed for low-latency caching. It is more suitable for storing larger files and objects, but not for serving high-performance cached query results.
- D. Incorrect.
Firestore does not have a built-in caching mechanism specifically for serving cached results across multiple function invocations. Caching at the application level using a tool like Redis is more appropriate.