Google Professional Cloud Developer Question 68
Select 3Google Cloud PlatformYou are developing a serverless application on Google Cloud using Cloud Functions. During a cost review, you notice that your Cloud Functions are incurring high costs due to excessive invocations and unoptimized runtimes. What actions can you take to optimize both cost and resource usage for your Cloud Functions?
- A
Reduce the function's timeout duration to handle requests faster.
- B
Use Cloud Tasks to batch and queue requests before invoking the Cloud Function.
- C
Switch to a smaller memory allocation for the Cloud Function that matches its workload.
- D
Enable pre-warming of Cloud Functions to avoid cold start latency.
- E
Implement retries with exponential backoff to reduce unnecessary repeated invocations.
Show answer and explanation
Correct answers: B, C, E
Explanation
To optimize cost and resource usage for Cloud Functions, you can use strategies like batching and queuing requests with Cloud Tasks, allocating the appropriate amount of memory for your function to avoid over-provisioning, and using exponential backoff for retries to minimize unnecessary invocations. These actions help balance performance and cost-efficiency without compromising the application's functionality.
- A. Incorrect.
Reducing the function's timeout duration may result in requests timing out prematurely, which could increase costs due to repeated invocations or failed requests. This is not a cost optimization strategy.
- B. Correct.
Using Cloud Tasks to batch and queue requests can reduce the number of invocations and distribute workload more efficiently, leading to cost and resource optimization.
- C. Correct.
Switching to a smaller memory allocation that matches the workload can reduce per-invocation costs without impacting performance, making it an effective cost optimization technique.
- D. Incorrect.
Enabling pre-warming of Cloud Functions is not a feature provided by Google Cloud and would not optimize costs. Cold starts may impact latency but do not directly increase invocation costs.
- E. Correct.
Implementing retries with exponential backoff reduces unnecessary repeated invocations by spacing out retries intelligently, which can help reduce costs caused by transient failures.