Google Professional Cloud Developer Question 463
Single answerGoogle Cloud PlatformYou are developing a cloud-based application that integrates with a third-party API. The API occasionally returns rate-limit errors (HTTP 429). To handle these errors effectively and ensure your application retries requests without overwhelming the API, what is the best approach to implement?
- A
Retry immediately for all failed requests to minimize latency.
- B
Implement an exponential backoff strategy with a maximum retry limit.
- C
Retry requests indefinitely until the API responds successfully.
- D
Use a fixed delay between retries for all failed requests.
Show answer and explanation
Correct answer: B
Explanation
Exponential backoff is a widely recommended error-handling strategy when dealing with rate-limit errors like HTTP 429. It progressively increases the delay between retries, reducing the risk of overwhelming the API while ensuring resilience. Adding a maximum retry limit prevents excessive resource usage and infinite retry loops.
- A. Incorrect.
Retrying immediately for all failed requests can overwhelm the API and result in more rate-limit errors. This approach does not respect the rate-limit guidelines of the API.
- B. Correct.
An exponential backoff strategy with a maximum retry limit is the best practice for handling rate-limit errors. It helps reduce load on the API while ensuring requests are retried at increasing intervals.
- C. Incorrect.
Retrying requests indefinitely is not a good practice because it can cause indefinite delays and unnecessary resource consumption, especially if the API remains unavailable.
- D. Incorrect.
Using a fixed delay between retries may help reduce load on the API, but it is less effective compared to exponential backoff. Fixed delays do not adapt well to varying API response times or error rates.