Google Professional Cloud Developer Question 466
Single answerGoogle Cloud PlatformYou are developing a serverless application on Google Cloud that interacts with a third-party API to fetch user data. The API has a request limit of 100 requests per minute, and exceeding this limit results in an HTTP 429 Too Many Requests error. How should you design your error handling strategy to ensure the application can handle these errors effectively while minimizing downtime?
- A
Implement exponential backoff with jitter and retry the failed requests.
- B
Immediately retry the failed requests without any delay.
- C
Log the error and stop processing further requests to ensure compliance with the API limit.
- D
Retry the failed requests with a fixed delay of 1 second between attempts.
Show answer and explanation
Correct answer: A
Explanation
Exponential backoff with jitter is a best practice for handling errors like HTTP 429 Too Many Requests, especially when interacting with rate-limited APIs. It allows retries to be spaced out, reducing the load on the API and improving the success rate of subsequent requests. Jitter adds randomness to the delays, preventing simultaneous retries from multiple processes or threads.
- A. Correct.
This is the correct approach. Exponential backoff with jitter is a recommended pattern for handling rate-limited APIs. It helps distribute retry attempts over time, reducing the likelihood of another error caused by simultaneous retries.
- B. Incorrect.
Immediately retrying failed requests can overwhelm the API, leading to repeated failures and unnecessary resource consumption.
- C. Incorrect.
While logging errors is useful for debugging, stopping further processing is not a scalable approach and leads to application downtime.
- D. Incorrect.
A fixed delay does not account for dynamic rate limits or contention, increasing the likelihood of repeated 429 errors.