Google Professional Cloud Developer Question 467
Single answerGoogle Cloud PlatformYou are developing a serverless application on Google Cloud that interacts with a third-party API. Occasionally, the API fails with a 503 Service Unavailable error due to high load. To handle these errors effectively, you decide to implement an exponential backoff strategy. Which approach ensures proper error handling in this scenario?
- A
Retry the request immediately after the first failure to ensure minimal latency.
- B
Retry the request with increasing delays after each failure, capping the delay at a maximum limit.
- C
Retry the request with a fixed delay between attempts, regardless of the number of failures.
- D
Stop retrying after the first failure and log the error for manual intervention.
Show answer and explanation
Correct answer: B
Explanation
Exponential backoff is a strategy where the delay between retries increases exponentially with each failure, often with a maximum cap to prevent indefinite delays. In the case of transient errors like 503, exponential backoff helps reduce the load on the failing service while giving it time to recover, improving the overall reliability of your application.
- A. Incorrect.
Retrying immediately does not account for the load issue on the third-party API and might exacerbate the problem, leading to more failures.
- B. Correct.
Using exponential backoff with a capped delay is the recommended approach for handling transient errors like 503, as it allows the system to recover while preventing excessive retries.
- C. Incorrect.
A fixed delay does not adapt to the increasing likelihood of persistent failures in high-load scenarios, making it less efficient than exponential backoff.
- D. Incorrect.
Stopping after the first failure and logging the error does not address transient errors and can result in a degraded user experience.