Google Professional Cloud Developer Question 464
Single answerGoogle Cloud PlatformYou have a Google Cloud application that interacts with a third-party API to process user requests. The API occasionally returns HTTP 429 (Too Many Requests) errors during periods of high usage. What is the best approach to handle these errors and ensure your application remains resilient?
- A
Retry the request immediately with the same payload until it succeeds.
- B
Implement an exponential backoff strategy with retries for HTTP 429 errors.
- C
Log the error and stop processing any further requests to avoid overloading the API.
- D
Switch to a different third-party API provider if errors persist.
Show answer and explanation
Correct answer: B
Explanation
When dealing with rate-limiting errors such as HTTP 429, an exponential backoff strategy is the recommended approach. This involves retrying failed requests with gradually increasing intervals, which helps reduce the risk of overloading the API and improves the chances of successful retries. This approach aligns with Google Cloud best practices for building resilient applications.
- A. Incorrect.
Retrying immediately without any delay risks overwhelming the third-party API further, which could lead to more failures or even temporary bans.
- B. Correct.
Using an exponential backoff strategy with retries is a best practice for handling rate-limiting errors (such as HTTP 429). It allows the system to retry requests with increasing delays, reducing the load on the third-party API and increasing the likelihood of success over time.
- C. Incorrect.
Logging the error is important, but stopping all further processing is unnecessary and could lead to degraded application performance for other users.
- D. Incorrect.
Switching to a different third-party API is not a practical solution for transient rate-limiting issues. It may also involve significant work to re-integrate with another provider.