question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Need some recommendations when Gmail API batch request returns 429 responses

See original GitHub issue

hello,

I have a multitenant application which does email synchronization with local database to cache user emails. Service is using GmailService for email synchronization with my local database. When cache is invalidated I need to do full synchronization.

For this first I call (in the loop using NextPageToken for 2nd and further pages):

service.Users.Messages.List("me")

to find out message id’s and then for each received message I build a batch request to get all details:

_request.Queue<Message>(
    _service.Users.Messages.Get("me", messageId),
    (message, error, index, response) =>
    {
        if (error != null)
        {
            var id = _ids[index];
            _messages.Add(new GmailMessage { Id = id, Error = error });
        }
        else
        {
            _messages.Add(new GmailMessage { Id = message.Id, Message = message });
        }
    });

Sometimes for some of these messages in the batch I get errors like:

Failed to receive message with id [xxxxxxxxxxxxxxx]. Error: Google.Apis.Requests.RequestError
Too many concurrent requests for user [429]
Errors [
	Message[Too many concurrent requests for user] Location[ - ] Reason[rateLimitExceeded] Domain[global]
]

Since only some messages are failing (like 60 out of 100 in the batch). I am not sure how to deal with these?

  • How long should I wait before retrying?
  • Should I do retry only for failed messages or for a whole batch. Not sure about this since I am storing HistoryId for later to find out changes since last sync, and in this case not clear if I can use it because of these errors. Lets imagine I will store it - but I won’t succeed in retrying for some reason - it will mean that I have HistoryId which assumes my failed messages are included, but actually it is not. So probably I cannot continue with the sync until I get retries solved?

Still its a bit strange to get those half failing because of this error as I am sending a “single” request, still I understand that each of these are individual ones at the end…

Thanks for any recommendations 😃

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
amanda-tarafacommented, Nov 4, 2021

As an FYI: A note on the recommended batch size has been added on the general batch documentation: https://developers.google.com/gmail/api/guides/batch#overview.

Thanks for flagging.

1reaction
amanda-tarafacommented, Oct 19, 2021

I’ve created an internal issue for the note on the recommended batch size to be included on the general batch documentation. Thanks for flagging.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolve errors | Gmail
If these limits are exceeded, a HTTP 429 Too Many Requests "User-rate limit exceeded" "(Mail sending)" error is returned with time to retry....
Read more >
Gmail API error 429 rateLimitExceeded even where is no ...
I think what's happening is you're making too many requests all at the same time. You can see your error in Gmail Per-User...
Read more >
429 Too many concurrent requests for user · Issue #1
Hi @zoellner , I'm using the library and find it exactly suitable to my need. However, i'm getting the above error despite using...
Read more >
How to run CRuX API query in batch?
The downside of batching this way is that you need additional logic to extract all of the results and resend any failures in...
Read more >
HTTP status and error codes for JSON | Cloud Storage
The following document provides reference information about the status codes and error messages that are used in the Cloud Storage JSON API.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found