Google Professional Cloud Developer Question 468
Single answerGoogle Cloud PlatformYou are building a cloud-based application on Google Cloud that interacts with a third-party API. The API has rate limits, and occasionally requests fail due to temporary errors such as HTTP 429 (Too Many Requests) or 503 (Service Unavailable). What is the best practice to handle these errors while ensuring the reliability of your service?
- A
Implement exponential backoff with retries for such errors.
- B
Immediately retry the request in a loop until it succeeds.
- C
Log the error and terminate the operation without retrying.
- D
Switch to a different API endpoint when such errors occur.
Show answer and explanation
Correct answer: A
Explanation
When dealing with APIs that have rate limits and transient errors, implementing exponential backoff with retries is a best practice. Exponential backoff introduces increasing delays between retry attempts, which helps to minimize the load on the API and allows time for the issue to resolve. This approach is particularly effective for errors like HTTP 429 and 503 that are temporary in nature.
- A. Correct.
This is the correct answer. Exponential backoff is a widely recommended best practice when dealing with transient errors, as it reduces the load on the API and increases the chance of success.
- B. Incorrect.
This is incorrect because immediate retries can overwhelm the API and violate its rate limits, leading to more errors and degraded performance.
- C. Incorrect.
This is not recommended because transient errors are temporary, and retrying with proper handling (e.g., exponential backoff) can often resolve the issue.
- D. Incorrect.
This is incorrect because switching API endpoints is not a standard practice for handling transient errors, and most APIs do not provide multiple interchangeable endpoints.