7
votes

We have an application that uses the Gmail API to access emails in Gmail.

Randomly we got the following error message

Google.Apis.Requests.RequestError Rate Limit Exceeded [429] Errors [ Message[Rate Limit Exceeded] Location[ - ] Reason[rateLimitExceeded] Domain[usageLimits] ]

Which we then retry in our code on error event and got

Google.Apis.Requests.RequestError Backend Error [500] Errors [ Message[Backend Error] Location[ - ] Reason[backendError] Domain[global] ]

which we then retry in our code on error event (we try 3 times) and it worked as expected.

There is some issue with the Gmail API backend here. we are making < 1000 Gmail API calls per day and nothing concurrent so I can't see that we have breached any limits.

Anybody else encountering this strange behaviour?

Here is the code that is being called

 UsersResource.MessagesResource.GetRequest gr = gs.Users.Messages.Get(emailAccount, msgId);
 {
        gr.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Raw;
        Message m = new Message();
        try
        {
            m = gr.Execute();
        }
 }
2
This seems like a discussion question, and thus isn't appropriate for Stack Overflow.Greg
What types of requests are you making? Using batched calls?Eric D
Hi Eric, was just a simple Message get - nothing batched. I'm thinking is a glitch in the google backend with misleading error message.PNC
We got the same random Exceptions. I know this is an old post, but did someone find any workaround?F3L1X79
Hi @F3L1X79 - no workaround - still occurs, retry is the only solution that we have found. Error is very rare though now.PNC

2 Answers

1
votes

The Gmail API has the same daily usage limit that applies to all requests made from your application, as well as per-user rate limits.

  • Daily Usage 1,000,000,000 quota units per day Per User Rate Limit
  • 250 quota units per user per second, moving average (allows short bursts)

Exceeding a rate limit (going to fast) will cause an HTTP 403 or HTTP 429 Too Many Requests response and your app should respond by retrying with exponential backoff.

The 500 errors are server hiccups the server took to long to respond so it timed out your request. The solution for this is the same as the solution for the above error you should implement exponential backoff and try again.

Exponential backoff is a standard error handling strategy for network applications in which the client periodically retries a failed request over an increasing amount of time. If a high volume of requests or heavy network traffic causes the server to return errors, exponential backoff may be a good strategy for handling those errors. Conversely, it is not a relevant strategy for dealing with errors unrelated to rate-limiting, network volume or response times, such as invalid authorization credentials or file not found errors.

Used properly, exponential backoff increases the efficiency of bandwidth usage, reduces the number of requests required to get a successful response, and maximizes the throughput of requests in concurrent environments.

The flow for implementing simple exponential backoff is as follows.

  1. Make a request to the API
  2. Receive an error response that has a retry-able error code
  3. Wait 1s + random_number_milliseconds seconds
  4. Retry request
  5. Receive an error response that has a retry-able error code
  6. Wait 2s + random_number_milliseconds seconds
  7. Retry request
  8. Receive an error response that has a retry-able error code
  9. Wait 4s + random_number_milliseconds seconds
  10. Retry request
  11. Receive an error response that has a retry-able error code
  12. Wait 8s + random_number_milliseconds seconds
  13. Retry request
  14. Receive an error response that has a retry-able error code
  15. Wait 16s + random_number_milliseconds seconds
  16. Retry request
  17. If you still get an error, stop and log the error.
0
votes

For anyone that might be trying to figure out why they are getting rate limited, also know that there is a bandwidth limit of about 750mb/hour or 2500mb/day. This limit is shared across ALL applications that connect to that users account (IMAP, POP, API). I believe even Gmail usage counts against this. If some other application is eating up the users quota, your application will receive this same rate limit.